|
Re: How to create a PDF report using designer? [message #118947 is a reply to message #118490] |
Fri, 27 January 2006 17:26 |
Eclipse User |
|
|
|
Originally posted by: mlorenz.nc.rr.com
Here's an example:
protected String format =PDF_FORMAT; //default PDF
public static final String PDF_FORMAT =
HTMLRenderOption.OUTPUT_FORMAT_PDF;
public static final String HTML_FORMAT =
HTMLRenderOption.OUTPUT_FORMAT_HTML;
protected static EngineConfig config;
public static ReportEngine ENGINE; //only create ONE engine for ALL
reports
/**
* Set up for BIRT report generation. Subclasses will
* do the actual generation based on their own designs,
* but using the one and only engine I create.
*/
static { //static initializer block
config = new EngineConfig( );
config.setEngineHome( "C:\\BIRT\\birt-runtime-2_0_0\\Report Engine"
); //TODO Set CORRECT home!!
//only create ONE engine for ALL reports
ENGINE = new ReportEngine( config );
// Create the emitter configuration.
HTMLEmitterConfig hc = new HTMLEmitterConfig( );
// Use the "HTML complete" image handler to write the files to disk.
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler( );
hc.setImageHandler( imageHandler );
// Associate the configuration with the HTML output format.
config.setEmitterConfiguration( HTML_FORMAT, hc );
}
/**
* Create a formatted output file using a BIRT .rptdesign XML file.
*/
public void generate() {
//------ Run reports
//--> IF params are needed for the report,
// add logic at
http://eclipse.org/birt/index.php?page=deploy/engine.html
// Output can be HTML or PDF. PDF is default.
IReportRunnable report = null;
try {
report = ENGINE.openReportDesign( getDesignFilepath() );
} catch (EngineException e) {
e.printStackTrace();
return;
}
// Create a separate task for EACH report
IRunAndRenderTask task = ENGINE.createRunAndRenderTask( report );
// Set up options.
HTMLRenderOption options = new HTMLRenderOption( );
// HTML (if specified) or PDF (default)
options.setOutputFormat( format );
String outputPath = "C:\\BIRT\\"; //TODO change to deployment location
outputPath = outputPath + getOutputFilename();
options.setOutputFileName(outputPath);
task.setRenderOption( options );
// Set parameter values using a HashMap. Parameters are name/value pairs.
// The values must be Java objects of the correct type.
HashMap params = getParameters(); //each report has its own params
task.setParameterValues( params );
task.validateParameters();
// Run the report.
try {
task.run( );
} catch (EngineException e) {
e.printStackTrace();
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02835 seconds