cancel
Showing results for 
Search instead for 
Did you mean: 

Bad files when exporting reports to PDF with CR4E

Former Member
0 Kudos

<p>Hello,</p><p>Have any of you successfully used CR4E to create a report and report viewer that produces a valid PDF export? I attempted this and the report looks fine, but when I export it to a PDF and attempt to open it, I get an Adobe Reader error message stating "There was an error opening this document. The file is damaged and could not be repaired." I am using Adobe Reader 7.0.8.</p><p>Thanks,</p><p>Matt</p>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

<p>&nbsp;</p><p>On the support site, search for KBase<span style="margin-left: 5px">4595908. </span></p><p><span style="margin-left: 5px">This problem happens on newer Java Web App Servers, including WebSphere 6, Tomcat 5.5, WebLogic 9.2 and Oracle OC4J 10g.</span></p><p>It occurs because CrystalReportViewer streams the PDF file to Response output stream, while JSP text is output to the Writer. These conflict. </p><p>If you open the corrupted PDF file in a text editor, do you see HTML text appended to the end? </p><p>Older versions of Java Web App Servers merely logged the conflict. Newer ones, when it detects that the output stream has been written to, and so the Writer should not be written to, then writes an HTML error page to the Writer. This is, ironically, conformant behavior.</p><p>The workaround is to eliminate any output to the Writer by eliminating all characters (including whitespace) from your jsp page outside of the java tags. This doesn&#39;t work for Oracle. For that, you&#39;ll have to invoke CrystalReportViewer in a servlet, and not a JSP, to eliminate writing to JSPWriter altogether.</p><p>TUeda </p><p>&nbsp;</p>

SJohnson
Employee
Employee
0 Kudos

<p>Hi Matt,</p><p> Are you using WebSphere 6.0.x by any chance? If so, there is a known issue that results in an OutputStream error message that is written to the PDF file rather than the App servers log file. To resolve this issue it is necessary to include the viewer code (or PDF export code) on a JSP page that has no other HTML content (including line breaks or whitespaces). Just the JSP code itself. If the viewer is embedded in another page then you may need to use IFrames.</p><p>We are looking to resolve this issue in the next release of our product, however we have only seen this issue occur with WAS 6.0.x due to it&#39;s strict adherence to the J2EE spec.</p><p>Give this a try and let me know if it works on your end. </p><p>Regards,<br />Sean Johnson (CR4E Product Manager) <br /><strong><br /><a href="http://www.eclipseplugincentral.com/Web_Links-index-req-ratelink-lid-639.html">Rate this plugin @ Eclipse Plugin Central</a></strong> </p>

Former Member
0 Kudos

<p>Thank you Sean! I am using WAS 6.0.2, but I can&#39;t verify the fix you mention as I am not sure which JSP I need to remove the whitespace from. Can you give me some more info on this? </p><p>I am experimenting with CR4E as I am in the architectural design stage for a new project, so I don&#39;t really understand the CR4E object model yet.  I created my report viewer JSP from the report, and the following JSP code was generated. I need to remove the white space from this JSP?</p><p>Thank you again.</p><p>Matt</p><font size="2" color="#bf5f3f"><%@</font><font size="2" color="#3f7f7f">page </font><font size="2" color="#7f007f">import</font><font size="2">=</font><font size="2" color="#2a00ff">"com.businessobjects.samples.JRCHelperSample,</font><font size="2" color="#2a00ff"> <p align="left">com.crystaldecisions.report.web.viewer.CrystalReportViewer,</p><p align="left">com.crystaldecisions.reports.sdk.ReportClientDocument,</p><p align="left">com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,</p><p align="left">com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase,</p><p align="left">com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,</p><p align="left">com.faweb.Company,</p><p align="left">java.util.ArrayList,</p><p align="left">java.util.List"<font size="2" color="#bf5f3f">%><%</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// This sample code calls methods from the JRCHelperSample class, which </font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// contains examples of how to use the BusinessObjects APIs. You are free to </font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// modify and distribute the source code contained in the JRCHelperSample class. </font></p></font><font size="2" color="#7f0055">try</font>{ String reportName = "Report2.rpt";

ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);

<font size="2" color="#7f0055">if</font>(clientDoc ==<font size="2" color="#7f0055">null</font>) {

// Report can be opened from the relative location specified in the CRConfig.xml, or the report location

// tag can be removed to open the reports as Java resources or using an absolute path

// (absolute path not recommended for Web applications).

clientDoc =<font size="2" color="#7f0055">new</font>ReportClientDocument();

// Open report

clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);

// ****** BEGIN LOGON DATASOURCE SNIPPET ****************

{

// Database username and password

String userName = "db2inst1"; // TODO: Fill in database user

String password = "######"; // TODO: FIll in password

// logon to database

JRCHelperSample.logonDataSource(clientDoc, userName, password);

}

// ****** END LOGON DATASOURCE SNIPPET ****************

// ****** BEGIN POPULATE WITH POJO SNIPPET ****************

{

// **** POPULATE MAIN REPORT ***</font></p></font><font size="2"><p align="left">{</p><p align="left"><font size="2" color="#3f7f5f">// Populate POJO data source</font></p></font><font size="2">String className = </font><font size="2" color="#2a00ff">"com.faweb.Company"</font><font size="2">;</font><font size="2"> <p align="left"><font size="2" color="#3f7f5f">// Look up existing table in the report to set the datasource for and obtain its alias. This table must</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// have the same schema as the Resultset that is being pushed in at runtime. The table could be created</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// from a Field Definition File, a Command Object, or regular database table. As long the Resultset</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// schema has the same field names and types, then the Resultset can be used as the datasource for the table.</font></p></font><font size="2">String tableAlias = </font><font size="2" color="#2a00ff">"Company"</font><font size="2">;</font><font size="2"> <p align="left"><font size="2" color="#3f7f5f">//Create a dataset based on the class com.faweb.Company</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">//If the class does not have a basic constructor with no parameters, make sure to adjust that manually</font></p></font><font size="2">List dataSet = </font>new<font size="2"> ArrayList();</font><font size="2"> <p align="left">dataSet.add(new* Company(0, "Dummy"));

// dataSet.add(new Company());

// dataSet.add(new Company());

// dataSet.add(new Company());

// dataSet.add(new Company());

//Push the resultset into the report (the POJO resultset will then be


the runtime datasource of the report)

JRCHelperSample.passPOJO(clientDoc, dataSet, className, tableAlias, "");

}

}

// ****** END POPULATE WITH POJO SNIPPET ****************

// Store the report document in session

session.setAttribute(reportName, clientDoc);

}

// ****** BEGIN CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************

{

// Create the CrystalReportViewer object

CrystalReportViewer crystalReportPageViewer =<font size="2" color="#7f0055">new</font>CrystalReportViewer();

// set the reportsource property of the viewer

IReportSource reportSource = clientDoc.getReportSource();

crystalReportPageViewer.setReportSource(reportSource);

// set viewer attributes

crystalReportPageViewer.setOwnPage(<font size="2" color="#7f0055">true</font>);crystalReportPageViewer.setOwnForm(<font size="2" color="#7f0055">true</font>);

// Apply the viewer preference attributes

// Process the report

crystalReportPageViewer.processHttpRequest(request, response, application,<font size="2" color="#7f0055">null</font>);

}

// ****** END CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************

// ****** BEGIN EXPORT PDF SNIPPET ***************</font></p></font><font size="2"><p align="left">{</p><p align="left">IReportSource reportSource = clientDoc.getReportSource();</p>JRCHelperSample.exportPDF(reportSource, request, response, config.getServletContext(), </font>true*);

}

// ****** END EXPORT PDF SNIPPET ***************</font></p></font><font size="2">} </font>catch* (ReportSDKExceptionBase e) {

out.println(e);

}

SJohnson
Employee
Employee
0 Kudos

<p>Hi Matt,</p><p> Yes, this should be the one you need to remove the whitespace from. Specifically, the workaround should be applied to the JSP page that creates the CrystalReportViewer object and calls the processHttpRequest() method. </p><p>If your code is designed to export using the ReportExportControl object then the workaround would be applied to the JSP page that includes the instantiation of the ReportExportControl object and that also calls the export() method.</p><p>Give this a try and let me know if this resolves the issue. </p><p>Regards,<br />Sean Johnson (CR4E Product Manager) <br /><br /> <a href="http://www.eclipseplugincentral.com/Web_Links-index-req-ratelink-lid-639.html">Rate this plugin @ Eclipse Plugin Central</a> </p>

Former Member
0 Kudos

Thanks Sean, but I am still at a loss here. Besides the above JSP code, all I have is a class method (below) that actually performs the export. I cannot get this to work or figure out what is sending the whistespace to the "out" object. Any ideas?

publicstaticvoidexportPDF(IReportSource reportSource, HttpServletRequest request, HttpServletResponse response, ServletContext context, booleanattachment)throwsReportSDKExceptionBase{

// PDF export allows page range export. The following routine ensures

// that the requested page range is valid

*PDFExportFormatOptions pdfOptions = </font><font size="2" color="#7f0055">new</font><font size="2"> PDFExportFormatOptions();</font></font><font size="2"> <p align="left">ExportOptions exportOptions = <font size="2" color="#7f0055">new</font><font size="2"> ExportOptions();<strong>exportOptions.setExportFormatType(ReportExportFormat.</strong></font></p></font>+<font size="2" color="#0000c0">PDF</font>+<font size="2">); </font><font size="2"><p align="left">exportOptions.setFormatOptions(pdfOptions);</p><strong>ReportExportControl reportExportControl = </strong></font><font size="2" color="#7f0055">new</font><font size="2"> ReportExportControl();</font><font size="2"> <p align="left">reportExportControl.setReportSource(reportSource);</p><p align="left">reportExportControl.setExportOptions(exportOptions);</p><p align="left"><font size="2" color="#3f7f5f">// ExportAsAttachment(true) prompts for open or save; false opens the report</font></p></font><font size="2"><p align="left"><font size="2" color="#3f7f5f">// in the specified format after exporting.</font></p></font><font size="2"><p align="left">reportExportControl.setExportAsAttachment(attachment);</p><p align="left"><font size="2" color="#3f7f5f">// Export the report</font></p></font><font size="2"><p align="left">reportExportControl.processHttpRequest(request, response, context, *null);

 

Thanks!

 Matt