Automatically open a rendered report [message #985725] |
Thu, 15 November 2012 20:12 |
Christoph Spielmann Messages: 5 Registered: November 2012 |
Junior Member |
|
|
Hi,
I have the following code to run and render my report designs:
private void runReport(String reportFilename, File outputFile, Map<String,Object> reportParameters) throws EngineException, IOException {
//Initialize the engine configuration
EngineConfig config = new EngineConfig();
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
//Create the report engine
IReportEngine engine = factory.createReportEngine(config);
//Open report design
URL reportUrl = SkischulApplicationWindow.class.getResource(reportFilename);
InputStream reportInputStream=reportUrl.openStream();
IReportRunnable design = engine.openReportDesign(reportInputStream);
IRunTask runTask = engine.createRunTask(design);
runTask.setParameterValues(reportParameters);
runTask.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, SkischulApplicationWindow.class.getClassLoader());
runTask.run(outputFile.getAbsolutePath()+".tmp");
//set general render-options
IRenderOption options = new RenderOption();
options.setOutputFormat("pdf");
options.setOutputFileName(outputFile.getAbsolutePath());
//pdf-rendering specific options
PDFRenderOption pdfOptions = new PDFRenderOption( options );
pdfOptions.setOption( IPDFRenderOption.FIT_TO_PAGE, new Boolean(true) );
pdfOptions.setOption( IPDFRenderOption.PAGEBREAK_PAGINATION_ONLY, new Boolean(true) );
pdfOptions.closeOutputStreamOnExit(true);
IReportDocument reportDocument=engine.openReportDocument(outputFile.getAbsolutePath()+".tmp");
IRenderTask renderTask = engine.createRenderTask(reportDocument);
renderTask.setRenderOption(pdfOptions);
renderTask.render();
//clean up (close all tasks)
runTask.close();
renderTask.close();
//clean up close all documents streams...
reportDocument.getDesignStream().close();
reportDocument.close();
reportInputStream.close();
engine.destroy();
}
...
So far so good! The report runs and is rendered BUT i want/need to open the generated pdf-document, i do that with
Desktop.getDesktop().open(outputFile);
This works under Linux and Windows 7 BUT the customer is using Windows XP and in this case it explains that the file can't be opened because it is already opened by another program. So my guess was that somehow there must exist an unclosed stream to the pdf-file but whatever i try i still see two processes using the pdf-file under linux.
fuser /tmp/skischule1756477463905062751.pdf
/tmp/skischule1756477463905062751.pdf: 10150 10206
One process is the java-process and the other is the pdf-viewer. So how can i find out what is still having an open fd on the file? Or how can i force birt to release all allocated resources?
|
|
|
Re: Automatically open a rendered report [message #985749 is a reply to message #985725] |
Thu, 15 November 2012 23:01 |
|
This is from the api page at: http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php
The report engine is created through a factory supplied by the Platform. Before creating the engine, you should start the Platform, which will load the appropriate plug-ins. This is done by calling Platform.startup(config) that takes an EngineConfig object as argument. After using the engine, call Plaform.shutdown() function to do clean up work, which includes unloading the extensions. When shutting down the engine in some environments, it may also be required to call: RegistryProviderFactory.releaseDefault(); This should be added after the Platform.shutdown() method is called. You will need to import the org.eclipse.core.internal.registry.RegistryProviderFactory package. See Bugzilla 351052 for more details.
That said, generally you do not what to shutdown the engine or the platform unless you application is finished completely with running reports. If you open the report from a file do you get this same error? By that I mean do not use the stream.
Jason
|
|
|
Powered by
FUDForum. Page generated in 0.02529 seconds