Skip to main content



      Home
Home » Archived » BIRT » Help on PDF generation
Help on PDF generation [message #139637] Mon, 06 March 2006 10:08 Go to next message
Eclipse UserFriend
Originally posted by: m.ruas.cgiar.org

I am also new in BIRT.

I was able to create the HTML report based on my pre designed
reportName.rptdesign.
Now I want to create a PDF file instead of HTML file.

What should be changed I do not use any tomcat server or so on. It is just a
stand alone application working with MySQL DB.

The code below isn't working.

import java.io.ByteArrayOutputStream;
import java.util.HashMap;

import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;

import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.engine.api.EngineConstants;


public class ExecuteReport {
static void executeReport() throws EngineException
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

//Engine Configuration - set and get temp dir, BIRT home, Servlet
context
EngineConfig config = new EngineConfig();
config.setEngineHome( "D:/birt-runtime-2_0_1/Report Engine" );

//Create the report engine
ReportEngine engine = new ReportEngine( config );
//Open a report design - use design to modify design, retrieve
embedded images etc.
IReportRunnable design =
engine.openReportDesign("D:/work/test/MGISReport.rptdesign");

//Create task to run the report - use the task to execute and run
the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");

HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( contextMap );

//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputStream(outputStream);

options.setOutputFormat("PDF");

task.setRenderOption(options);
//run the report and destroy the engine
task.run();

engine.destroy();
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Re: Help on PDF generation [message #140034 is a reply to message #139637] Mon, 06 March 2006 17:05 Go to previous message
Eclipse UserFriend
Here is the code I use to create a pdf file. It is exactly the same as the
code I use to create an HTML report except for one thing. The
HTMLRenderOption.OUTPUT_FORMAT_PDF; is ...._HTML; instead of ...._PDF; for
my HTML Report. The commented out lines are for parameters. You can pick
through the code to find your answers or if you add your code that is
working for HTML I can look through it and see what needs changed to
output PDF.
Thanks

String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;
EngineConfig config = new EngineConfig();
config.setEngineHome(
"C:/Program Files/Eclipse/eclipse/birt-runtime-2_0_0/Report
Engine");
//Get rid of Info Messages, print warning and severe messages in
"address"
config.setLogConfig("C:/Program Files/Eclipse/eclipse",
java.util.logging.Level.WARNING);
HTMLEmitterConfig hc = new HTMLEmitterConfig();
HTMLCompleteImageHandler imageHandler = new
HTMLCompleteImageHandler();
hc.setImageHandler(imageHandler);
config.setEmitterConfiguration(format, hc);
ReportEngine engine = new ReportEngine(config);
String reportToRun =
"../Event_Tracking_Reports/entity_simple.rptdesign";
IReportRunnable report = null;
try
{
report = engine.openReportDesign(reportToRun);
}
catch(EngineException ee)
{
System.err.println("Report " + reportToRun + " not found!\n");
engine.destroy();
return;
}
//HashMap values = new HashMap();
//String type = "%";
//String gender = "%";
//String status = "%";
//String age1 = "0 years";
//String age2 = "1000 years";
//String sort1 = "sort_name";
//String sort2 = "entity_type";
//String url = "jdbc:ingres://localhost:S27/event_tracking";
//String userName = JOptionPane.showInputDialog("User Name");
//String password = JOptionPane.showInputDialog("Password");
//values.put("entity_type", type);
//values.put("gender",gender);
//values.put("status",status);
//values.put("age1",age1);
//values.put("age2",age2);
//values.put("sort1",sort1);
//values.put("sort2",sort2);
//values.put("URL",url);
//values.put("UserName",userName);
//values.put("Password",password);
//parseParams(engine, report, values);
IRunAndRenderTask task = engine.createRunAndRenderTask(report);
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(format);
String output = reportToRun.replaceFirst(".rptdesign", "." +
format);
options.setOutputFileName(output);
task.setRenderOption(options);
//task.setParameterValues(values);
try
{
task.run();
System.out.println("Created Report " + output + ".\n");
}
catch(EngineException ee1)
{
System.err.println("Report " + reportToRun + " run failed.\n");
System.err.println(ee1.toString());
}
engine.destroy();
Previous Topic:Getting 2.1M5 to run. Plugin not found.
Next Topic:Specify a specific Dataset to use
Goto Forum:
  


Current Time: Thu Jul 24 09:57:12 EDT 2025

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

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

Back to the top