Community
Participate
Working Groups
See also http://www.eclipse.org/forums/index.php/t/459265/ With the following code, I cannot rename the PDF file after the RenderTask: IReportDocument rptdoc = engine.openReportDocument(destName + ".rptdocument"); renderTask = engine.createRenderTask(rptdoc); try { IRenderOption options = new RenderOption(); options.setOutputFileName(destName); options.setOutputFormat(destFormatMapped); PDFRenderOption pdfOptions = new PDFRenderOption(options); pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES); pdfOptions.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true); pdfOptions.setOption(IPDFRenderOption.PDF_HYPHENATION, true); options.setOption(IRenderOption.CLOSE_OUTPUTSTREAM_ON_EXIT, true); renderTask.setRenderOption(options); renderTask.render(); } catch (EngineException ex) { throw new CancelWithMessage("BIRT RenderTask failed", ex); } finally { try { for (Object ex: renderTask.getErrors()) { log.error("BIRT RenderTask error", (Exception)ex); } renderTask.close(); renderTask = null; rptdoc.close(); } catch (Exception e) { log.error("Error closing BIRT RenderTask", e); } } // Next, try to rename the file. ... Looking at the BIRT source code, it looks like when you use the IRenderOption.setOutputFileName API, the resulting PDF file is NOT closed by birt when the RenderTask is finished, even if you explicitly set the CLOSE_OUTPUTSTREAM_ON_EXIT option; this option is only considered when passing an OutputStream instead of a filename. The funny thing is: I am not able to reproduce the error with RunAndRenderTask. I am not able to reproduce the error with BIRT 4.2.1 I am able to reproduce the error with BIRT 4.3.0 and separate RunTask/RenderTask. Please also note that the iText API example code (in chapter 1) expliticly close the FileOutputStream after calling iText (fos.close()). I was not able to find something similar in the BIRT source code.
As a workaround, one can use the following code: FileOutputStream fos = null; try { IRenderOption options = new RenderOption(); fos = new FileOutputStream(destName); final int BUFSIZE = 32768; options.setOutputStream(new BufferedOutputStream(fos, BUFSIZE)); options.setOutputFormat("PDF"); ... } finally { try { for (Object ex: renderTask.getErrors()) { log.error("BIRT RenderTask error", (Exception)ex); } renderTask.close(); renderTask = null; log.info("renderTask closed."); rptdoc.close(); log.info("rptdoc closed."); fos.close(); log.info("fos closed"); } catch (Exception e) { log.error("Error closing BIRT RenderTask", e); } } That is, use a FileOutputStream instead and take care of closing it.
the issue is not on RenderTask. The outputstream is not close correctly on the PDFRender. Run the same code using html and it works perfectly. The work around still fails some times.
there were more than one outputstream so it only close one, fix on Luna commit a86abe749fbbac32a7cabc56c081d2347c2110a1 Signed-off-by: sguan-actuate <sguan@actuate.com>
v