Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
page number in birt using java (PDF)
birt scree
Hi ,
I am creating pdf using birt. I need to display page number.How can i implement using java?
how do i know "sample.rptdesign" file carries total number of pdf pages?
Regards,
Anand
Find more posts tagged with
Comments
JasonW
You can open the report design in the designer, select the master page and add the page number auto text item to the header or footer. When you run the report using Java, use a run task that creates a rpt document then use a render task to render to pdf.
Here is a sample api program. If the app continues to run after running the report you may not want to do the shutdown logic. As starting up the BIRT runtime is expensive. Do the shudown logic when your app is ending. Create the BIRT engine only once (wrap in a singleton) for all classes to use.
package REAPI;
import java.util.Locale;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IPDFRenderOption;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class RunThenRenderTask {
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
IReportDocument document = null;
try{
config = new EngineConfig( );
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
design = engine.openReportDesign("Reports/Test.rptdesign");
IRunTask task = engine.createRunTask(design);
task.setLocale(new Locale("en", "US"));
task.run("output/resample/Test.rptdocument");
task.close();
document = engine.openReportDocument("output/resample/Test.rptdocument");
//HTMLRenderOption options = new HTMLRenderOption();
//options.setOutputFormat("odp");
//options.setOutputFileName("output/resample/ppttest.odp");
//options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
PDFRenderOption options = new PDFRenderOption();
options.setOutputFileName("output/resample/pdftest.pdf");
options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
options.setOutputFormat("pdf");
options.setOption(PDFRenderOption.PAGE_OVERFLOW, IPDFRenderOption.FIT_TO_PAGE_SIZE);
options.setOption( IRenderOption.HTML_PAGINATION,
Boolean.TRUE );
IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
rtask.close();
document.close();
engine.destroy();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
System.out.println("Finished");
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
RunThenRenderTask ex = new RunThenRenderTask( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
Jason
JasonW
BTW shudown logic is engine.destroy and Platform.shutdown commands.
Jason