mariog36 Posted April 4, 2011 Share Posted April 4, 2011 Hi I'm testing a .jasper in iReport and I have the correct .pdf, but I have a .war application where a place my .jasper and I get the same .pdf Can someone help me please? Link to comment Share on other sites More sharing options...
dgangstaz Posted April 5, 2011 Share Posted April 5, 2011 You create your pdf file programatically from your application? If yes, what's the code? Link to comment Share on other sites More sharing options...
mariog36 Posted April 5, 2011 Author Share Posted April 5, 2011 What I do is this:Do I have to compilate the jrxml every time I call it??? <%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">/*importamos las librerías de JasperReports*/<%@ page import="net.sf.jasperreports.engine.*" %><%@ page import="java.util.*" %><%@ page import="java.io.*" %><%@ page import="java.sql.*" %><%@ page import="java.text.DateFormat"%><%@ page import="java.text.ParseException"%><%@ page import="java.text.SimpleDateFormat"%><%@ page import="java.util.Date"%><% /*Parametros para realizar la conexión*/ Connection conexion; Class.forName("com.mysql.jdbc.Driver").newInstance(); conexion = DriverManager.getConnection("jdbc:mysql://localhost/wf", "root", "12345678"); /*Establecemos la ruta del reporte*/ File reportFile = new File(application.getRealPath("/reportes/nombre.jasper")); /* No enviamos parámetros porque nuestro reporte no los necesita asi que escriba cualquier cadena de texto ya que solo seguiremos el formato del método runReportToPdf*/ Map parameters = new HashMap(); String emp=request.getParameter("emp"); if(emp!=null){ parameters.put("nombre", "%"+emp+"%"); System.out.print(emp); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date pFecha = new Date(); pFecha=(Date)formatter.parse(request.getParameter("calInput1")); System.out.print("fecha->"+pFecha); parameters.put("fechaIni",pFecha); pFecha=(Date)formatter.parse(request.getParameter("calInput2")); parameters.put("fechaFin",pFecha); String rfc=request.getParameter("rfc"); if(rfc!=null){ parameters.put("rfc","%"+rfc+"%"); System.out.println("rfc->"+rfc); } String serie=request.getParameter("serie"); if(serie!=null){ parameters.put("serie","%"+serie+"%"); System.out.println("serie->"+serie); } String edicion=request.getParameter("edicion"); if(edicion!=null){ parameters.put("edicion","%"+edicion+"%"); System.out.println("edicion->"+edicion); } String tipo=request.getParameter("tipo"); if(tipo!=null){ parameters.put("tipo","%"+tipo+"%"); System.out.println("tipo->"+tipo); } String status=request.getParameter("status"); if(status!=null){ parameters.put("status","status"); System.out.println("status->"+status); } //PDF/// /*Enviamos la ruta del reporte, los parámetros y la conexión(objeto Connection)*/ byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,conexion); /*Indicamos que la respuesta va a ser en formato PDF*/ response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(bytes, 0, bytes.length); /*Limpiamos y cerramos flujos de salida*/ ouputStream.flush(); ouputStream.close(); //END PDF///%> Link to comment Share on other sites More sharing options...
dgangstaz Posted April 5, 2011 Share Posted April 5, 2011 I use the following code the generate a pdf to output stream from a custom datasource. A also load directelly the compiled .jasper file so you don't have to compile the .jrxml file for each run. is = ReportConstants.getPdfJasperFilename();ds = new JRBeanCollectionDataSource(getSortedBean()); try { JasperReport jasperReport = (JasperReport) JRLoader.loadObject(is); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds); JasperExportManager.exportReportToPdfStream(jasperPrint, os); } catch (JRException e) { e.printStackTrace(); logger.error(e); } Link to comment Share on other sites More sharing options...
mariog36 Posted April 5, 2011 Author Share Posted April 5, 2011 Plus I'm getting this error StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exceptionjava.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:717) at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:226) at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:187) at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:180) at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:237) at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:173) at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:124) at org.apache.jsp.reporte_jsp._jspService(reporte_jsp.java]:158) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106) Link to comment Share on other sites More sharing options...
cathyben3 Posted July 29, 2015 Share Posted July 29, 2015 You must be a developer and know much about PDF, I'm looking for control for converting PDF. I found PDF to Word converter and Excel to PDF convert, but I want to know is it possible to convert PDF to Excel or any control with it? Hope you can give some ideas on it. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now