Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Automatically open a rendered report
Automatically open a rendered report [message #985725] Thu, 15 November 2012 20:12 Go to next message
Christoph Spielmann is currently offline Christoph SpielmannFriend
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 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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
Previous Topic:Is there an XSL file associated with BIRT Report Designer?
Next Topic:Avoid Color in Series Palette
Goto Forum:
  


Current Time: Thu Apr 18 16:33:41 GMT 2024

Powered by FUDForum. Page generated in 0.01823 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top