Home
Analytics
PDF file Damaged
andrew.chu
I have a report design file that uses XML file as data source.
In iServer a report is created as PDF format without a problem when using small size xml data source.
But when there are more data in the xml, iServer creates a pdf file but when you acutally try to open it within the iServer Management Console a Viewer window(?) pop up and does nothing. Also, if you download the pdf file, the file seems to be damaged and won't open.
When you look at the file detail in the Management Console, it shows similar size and same page numbers,comparing with the one I generated using my application.
Not sure if this has anything to do with it but have following in one of the log;
[Thread-11, RequestID-Corinth--2011-02-17 11:19:54--2] 17-Feb-2011 11:24:53 AM org.eclipse.birt.report.engine.layout.emitter.PageDeviceRender log
WARNING: null
java.lang.NullPointerException
at com.lowagie.text.pdf.PdfWriter.addLocalDestination(PdfWriter.java:802)
at com.lowagie.text.pdf.PdfWriter$1.onKey(PdfWriter.java:794)
at com.lowagie.text.pdf.DestinationMap.forAllKeys(DestinationMap.java:128)
at com.lowagie.text.pdf.PdfWriter.addLocalDestinations(PdfWriter.java:789)
at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:853)
at com.lowagie.text.Document.close(Unknown Source)
at org.eclipse.birt.report.engine.emitter.pdf.PDFPageDevice.close(PDFPageDevice.java:186)
at org.eclipse.birt.report.engine.layout.emitter.PageDeviceRender.end(PageDeviceRender.java:144)
at org.eclipse.birt.report.engine.emitter.pdf.PDFRender.end(PDFRender.java:143)
at org.eclipse.birt.report.engine.layout.emitter.PageEmitter.end(PageEmitter.java:63)
at org.eclipse.birt.report.engine.nLayout.LayoutEngine.end(LayoutEngine.java:333)
at org.eclipse.birt.report.engine.api.impl.RenderTask$PageRangeRender.render(RenderTask.java:675)
at org.eclipse.birt.report.engine.api.impl.RenderTask.render(RenderTask.java:284)
at com.actuate.birt.report.engine.internal.ActuateRenderTask.render(ActuateRenderTask.java:50)
at com.actuate.reportapi.engine.birt.ViewReportTask.renderReport(Unknown Source)
at com.actuate.reportapi.engine.birt.ViewReportTask.doTask(Unknown Source)
at com.actuate.reportapi.engine.Task.execute(Unknown Source)
at com.actuate.reportapi.enginemanager.ThreadPool$ControlRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
[Thread-12] 17-Feb-2011 11:32:15 AM com.actuate.javaserver.HeartBeatTimer$HeartBeatTask checkHeartbeat
WARNING: Effective heartbeat clock interval was: 6 seconds.
[Thread-13, RequestID-Corinth--2011-02-17 11:30:06--3] 17-Feb-2011 11:34:50 AM org.eclipse.birt.report.engine.layout.emitter.PageDeviceRender log
WARNING: null
java.lang.NullPointerException
at com.lowagie.text.pdf.PdfWriter.addLocalDestination(PdfWriter.java:802)
at com.lowagie.text.pdf.PdfWriter$1.onKey(PdfWriter.java:794)
at com.lowagie.text.pdf.DestinationMap.forAllKeys(DestinationMap.java:128)
at com.lowagie.text.pdf.PdfWriter.addLocalDestinations(PdfWriter.java:789)
at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:853)
at com.lowagie.text.Document.close(Unknown Source)
at org.eclipse.birt.report.engine.emitter.pdf.PDFPageDevice.close(PDFPageDevice.java:186)
at org.eclipse.birt.report.engine.layout.emitter.PageDeviceRender.end(PageDeviceRender.java:144)
at org.eclipse.birt.report.engine.emitter.pdf.PDFRender.end(PDFRender.java:143)
at org.eclipse.birt.report.engine.layout.emitter.PageEmitter.end(PageEmitter.java:63)
at org.eclipse.birt.report.engine.nLayout.LayoutEngine.end(LayoutEngine.java:333)
at org.eclipse.birt.report.engine.api.impl.RenderTask$PageRangeRender.render(RenderTask.java:675)
at org.eclipse.birt.report.engine.api.impl.RenderTask.render(RenderTask.java:284)
at com.actuate.birt.report.engine.internal.ActuateRenderTask.render(ActuateRenderTask.java:50)
at com.actuate.reportapi.engine.birt.ViewReportTask.renderReport(Unknown Source)
at com.actuate.reportapi.engine.birt.ViewReportTask.doTask(Unknown Source)
at com.actuate.reportapi.engine.Task.execute(Unknown Source)
at com.actuate.reportapi.enginemanager.ThreadPool$ControlRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Please help!
Find more posts tagged with
Comments
averma
Hi andrew.chu,
If its available to you, can you check if the PDF is generated fine if the same data is sourced from a database or flat file etc?
Ashwini
Inswinger
After spending a lot of time on similar issue ...i got to know tht the solution for this is using pdfreader and similar classes from itext... i am using following code and now my pdf is generated quiet well ...i must mention just by using PDFRenderOption and passing output stream is not enough as per the servlet integration examples given for the birt web viewer ...<pre class='_prettyXprint _lang-auto _linenums:0'>
IReportRunnable design = engine.openReportDesign(sc.getRealPath("/reports") + "/" + "yourReport.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, YourClass.class.getClassLoader());
task.getAppContext().put("BIRT_VIEWER_HTTPSERVLET_REQUEST", req);
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
options = new PDFRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
options.setOutputStream(baos2);
options.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
options.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true);
task.setRenderOption(options);
task.run();
task.close();
PdfCopyFields copyFields = new PdfCopyFields(resp.getOutputStream());
copyFields.addDocument(new PdfReader(baos.toByteArray()));
copyFields.close();
</pre>
averma
Hi Inswinger,
Thanks for sharing your findings. If this bug can be recreated, I would suggest create a bug so that it can be fixed in upcoming release.
http://www.birt-exchange.org/org/resources/bug-reporting/
Ashwini
CBR
Just one note:
the line:
task.getAppContext().put("BIRT_VIEWER_HTTPSERVLET_REQUEST", req);
might be incorrect in API sense. I remember that there was some missspelling of the BIRT_VIEWER_HTTPSERVLET_REQUEST key which you are using to inject the request. That's why i always use the corresponding constant and not it's string representation.
Have a look at:
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.birt.doc.isv/engine/api/org/eclipse/birt/report/engine/api/EngineConstants.html
As you can see there is a missing L in the key.
You have to change the key to "BIRT_VIEWER_HTTPSERVET_REQUEST" or better use EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST
Inswinger
Thanks cbrell,<br />
<br />
But the code i shared now seems to be working for me. i think there is a need to update the documentation and examples which are shared for servlet integration. I didnt find any example which uses following code for taking the ouput stream ... otherwise what i had been doing so far was to just write the byte stream to the output stream which we get from reposonse...<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
Right Approach -
PdfCopyFields copyFields = new PdfCopyFields(resp.getOutputStream());
copyFields.addDocument(new PdfReader(baos.toByteArray()));
copyFields.close();
</pre>