Jump to content
Changes to the Jaspersoft community edition download ×

JRPdfExport


2004 IR Help

Recommended Posts

By: Scott - imnotscott

JRPdfExport

2005-09-01 09:34

I am a Jasper Newbie and could use a little help. I am working on a Struts project and have a few reports that I currently export to HTML. That part is working fine.

 

What I would like to do is to export the HTML report that has already run to PDF. I have created an pdfExporter action class with the following code snip:

 

String outFileName = "MPRIS Reports Export.pdf";

HttpSession session = request.getSession( );

if (session.getAttribute("JASPER_PRINT") != null) {

JasperPrint jasperPrint = (JasperPrint)session.getAttribute("JASPER_PRINT");

JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,outFileName);

exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);

exporter.exportReport();

}

 

When I hit that action, I get the following error dump:

java.lang.NoClassDefFoundError: com/lowagie/text/Document

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:293)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:262)

at report.PdfExportAction.perform(PdfExportAction.java:54)

at org.apache.struts.action.Action.execute(Action.java:420)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:509)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

at java.lang.Thread.run(Thread.java:534)

 

Can anyone help me figure this out?

 

 

 

 

 

 

By: Denny Valliant - xenden

RE: JRPdfExport

2005-09-01 18:43

I generally do something like this[1] in ColdFusion... should be pretty obvious how you'd convert it back to java. Don't know if it would work anyways tho, as I seem to remember a post about reusing jasper print objects and some type of trouble maybe... Not at a point where I could try it and see, so no real answer for you. May you find the way! PS i'm not sure if the below code is even "best practice" for exporting jaspers. May be using depricated whatnots, etc... Oh well. Good luck!

 

1.

jasperPrint = jasperFillManager.fillReport(jasperReport, parameters, jRXmlDataSource);

 

jasperExportManager = CreateObject("java","net.sf.jasperreports.engine.JasperExportManager");

expparam = CreateObject("java", "net.sf.jasperreports.engine.JRExporterParameter");

//exporter.setParameter(expparam.OUTPUT_FILE_NAME,outfile);

if (exportType is "pdf") {

argy = jasperExportManager.exportReportToPdf(jasperPrint);

} else if(exportType is "rtf") {

argy = jasperExportManager.exportReportToRtf(jasperPrint);

} else if(exportType is "xls") {

argy = jasperExportManager.exportReportToXls(jasperPrint);

}

 

 

 

 

By: Scott - imnotscott

RE: JRPdfExport

2005-09-06 04:44

I'm not sure why this won't work. As a test, I stopped using the action class and put the code right into a JSP. At this point in the application I have already filled the report and exported it to HTML. I added a button that links to a JSP with the following code:

if (session.getAttribute("JASPER_PRINT") != null) {

JasperPrint jasperPrint = (JasperPrint)session.getAttribute("JASPER_PRINT");

JasperExportManager jasperExportManager = new net.sf.jasperreports.engine.JasperExportManager();

byte[] bytes = jasperExportManager.exportReportToPdf(jasperPrint);

response.setContentType("application/pdf");

response.setContentLength(bytes.length);

ServletOutputStream ouputStream = response.getOutputStream();

ouputStream.write(bytes, 0, bytes.length);

ouputStream.flush();

ouputStream.close();

}

 

 

When that runs I get this:

java.lang.NoClassDefFoundError: com/lowagie/text/Document

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:293)

at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:241)

at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdf(JasperExportManager.java:188)

at _report._pdfViewer._jspService(pdfViewer.jsp:11)

[/report/pdfViewer.jsp]

at com.orionserver[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].http.OrionHttpJspPage.service(OrionHttpJspPage.java:57)

at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:347)

at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)

at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)

at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

at java.lang.Thread.run(Thread.java:534)

 

I'm a real newbie, so I suspect that my problem is probably pretty simple but I can't figure it out. Help please?

 

 

 

 

By: Dejan Nikolic - decky

RE: JRPdfExport

2005-09-07 00:10

Try to add itext jar into your classpath.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...