Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Need help to generate PDF Report (Need help to generate PDF Report )
Need help to generate PDF Report [message #788967] Thu, 02 February 2012 12:54 Go to next message
balachandar sivalingam is currently offline balachandar sivalingamFriend
Messages: 9
Registered: January 2012
Junior Member
Hi,

I am trying to generate pdf report.

It is generating the pdf file in the path...but it is not rendered automatically..also as i tried to open the pdf file manually...

Adobe Reader could not open 'sample.pdf'" because it is either not a supported file type or because the file has been corrupted (for example, it was sent as an email attachment and wasn't correctly decoded)

Please help me to resolve the issue....Please provide sample code or link if possible.

I am using the below code.(I am executing the code in tomcat server(struts2))



EngineConfig conf = new EngineConfig();
ReportEngine eng = null;
IReportRunnable design = null;
IRunAndRenderTask task = null;
String reportName = "sample.rptdesign";
String path = servletContext.getRealPath("");
String reportDirectoryPath = path + System.getProperty("file.separator") + "birtreports";

String engineHome = path + System.getProperty("file.separator") + "WEB-INF";
conf = new EngineConfig();
conf.setEngineHome(engineHome);
eng = new ReportEngine( conf );


String reportPath = path + System.getProperty("file.separator") + "birtreports" + System.getProperty("file.separator") + reportName ;

try
{
design = eng.openReportDesign(reportPath);
}
catch (Exception e)
{
System.err.println("An error occured during the opening of the report file!");
e.printStackTrace();
}
//With the file open, create the Run and Render task to run the report
task = eng.createRunAndRenderTask(design);


String fileName = reportDirectoryPath + System.getProperty("file.separator") + "sample"+ ".pdf";

System.out.println("File Name is : " + fileName);


PDFRenderOption pdfOptions = new PDFRenderOption( );
pdfOptions.setOption( IPDFRenderOption.FIT_TO_PAGE, new Boolean(true) );
pdfOptions.setOption( IPDFRenderOption.PAGEBREAK_PAGINATION_ONLY, new Boolean(true) );
pdfOptions.setOutputFileName(fileName);


task.setRenderOption(pdfOptions);
//Set parent classloader for engine
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ReportAction.class.getClassLoader());

//Cross our fingers and hope everything is set
try
{
task.run();
task.close();
}
catch (Exception e)
{
System.err.println("An error occured while running the report!");
e.printStackTrace();
//System.exit(-1);
}

//Yeah, we finished. Now destroy the engine and let the garbage collector
//do its thing
System.out.println("All went well. Closing program!");
eng.destroy();


Thanks,
balachandar
Re: Need help to generate PDF Report [message #789285 is a reply to message #788967] Thu, 02 February 2012 19:29 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Are you running this as a servlet? What version are you using?
Have a look at this wiki page:
http://wiki.eclipse.org/Servlet_Example_%28BIRT%29_2.1

Jason

On 2/2/2012 7:54 AM, balachandar sivalingam wrote:
> Hi,
>
> I am trying to generate pdf report.
>
> It is generating the pdf file in the path...but it is not rendered
> automatically..also as i tried to open the pdf file manually...
>
> Adobe Reader could not open 'sample.pdf'" because it is either not a
> supported file type or because the file has been corrupted (for example,
> it was sent as an email attachment and wasn't correctly decoded)
>
> Please help me to resolve the issue....Please provide sample code or
> link if possible.
>
> I am using the below code.(I am executing the code in tomcat
> server(struts2))
>
>
>
> EngineConfig conf = new EngineConfig();
> ReportEngine eng = null;
> IReportRunnable design = null;
> IRunAndRenderTask task = null;
> String reportName = "sample.rptdesign";
> String path = servletContext.getRealPath("");
> String reportDirectoryPath = path + System.getProperty("file.separator")
> + "birtreports";
> String engineHome = path + System.getProperty("file.separator") +
> "WEB-INF";
> conf = new EngineConfig();
> conf.setEngineHome(engineHome);
> eng = new ReportEngine( conf );
> String reportPath = path + System.getProperty("file.separator") +
> "birtreports" + System.getProperty("file.separator") + reportName ;
>
> try
> {
> design = eng.openReportDesign(reportPath); }
> catch (Exception e)
> {
> System.err.println("An error occured during the opening of the report
> file!");
> e.printStackTrace();
> }
> //With the file open, create the Run and Render task to run the report
> task = eng.createRunAndRenderTask(design);
> String fileName = reportDirectoryPath +
> System.getProperty("file.separator") + "sample"+ ".pdf";
> System.out.println("File Name is : " + fileName);
> PDFRenderOption pdfOptions = new PDFRenderOption( );
> pdfOptions.setOption( IPDFRenderOption.FIT_TO_PAGE, new Boolean(true) );
> pdfOptions.setOption( IPDFRenderOption.PAGEBREAK_PAGINATION_ONLY, new
> Boolean(true) );
> pdfOptions.setOutputFileName(fileName);
> task.setRenderOption(pdfOptions);
> //Set parent classloader for engine
> task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
> ReportAction.class.getClassLoader());
> //Cross our fingers and hope everything is set
> try
> {
> task.run();
> task.close();
> }
> catch (Exception e)
> {
> System.err.println("An error occured while running the report!");
> e.printStackTrace();
> //System.exit(-1);
> }
> //Yeah, we finished. Now destroy the engine and let the garbage collector
> //do its thing
> System.out.println("All went well. Closing program!");
> eng.destroy();
>
>
> Thanks,
> balachandar
Re: Need help to generate PDF Report [message #789523 is a reply to message #788967] Fri, 03 February 2012 04:22 Go to previous messageGo to next message
balachandar sivalingam is currently offline balachandar sivalingamFriend
Messages: 9
Registered: January 2012
Junior Member
Jason,

I am using birt 3.7.

I am trying to generate this report from User Defined Action Class which extends Struts 2 ActionSupport Class..From this Action class we can get the HttpServeltRequest,HttpServeltResponse, SevltContext if required.

For our project, I was asked to generate(export) report in these formats (pdf/excel/printable html).

I followed this link wiki.eclipse.org/Servlet_Example_(BIRT)_2.1

I will try with the link given by you.

Please clarify this....

Since I need to generate or export a same report in multiple type(pdf/excel/printable html), at the time of disigning report should we consider anything?

If you know any articles to export report in other formats(excel, word) please let me know.

What is the best book i can follow to become familiar on birt report?


Thanks,
balachandar
Re: Need help to generate PDF Report [message #789608 is a reply to message #789523] Fri, 03 February 2012 07:07 Go to previous messageGo to next message
balachandar sivalingam is currently offline balachandar sivalingamFriend
Messages: 9
Registered: January 2012
Junior Member
Jason,

I tried with the link provided by you. It's working fine.

As mentioned in the link, I used

options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);

Thank you very much.

-balachandar
Re: Need help to generate PDF Report [message #789965 is a reply to message #789523] Fri, 03 February 2012 16:18 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

If you want to export in many formats, make sure to use a run task and
then a render task. The reason for this is that for each of the formats
you will not have to re-run the report. If you use a runandrendertask
you will have to run the report for each format.

You may want to read over this:
http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php
and
http://www.birt-exchange.org/org/devshare/deploying-birt-reports/1344-eclipsecon-2011-api-examples/

For Books you may want to look at
"BIRT A Field Guide to Reporting" Version 3
"Integrating and Extending BIRT" Version 3

Jason


On 2/2/2012 11:22 PM, balachandar sivalingam wrote:
> Jason,
>
> I am using birt 3.7.
>
> I am trying to generate this report from User Defined Action Class which
> extends Struts 2 ActionSupport Class..From this Action class we can get
> the HttpServeltRequest,HttpServeltResponse, SevltContext if required.
>
> For our project, I was asked to generate(export) report in these formats
> (pdf/excel/printable html).
>
> I followed this link wiki.eclipse.org/Servlet_Example_(BIRT)_2.1
>
> I will try with the link given by you.
>
> Please clarify this....
>
> Since I need to generate or export a same report in multiple
> type(pdf/excel/printable html), at the time of disigning report should
> we consider anything?
>
> If you know any articles to export report in other formats(excel, word)
> please let me know.
>
> What is the best book i can follow to become familiar on birt report?
>
>
> Thanks,
> balachandar
Re: Need help to generate PDF Report [message #791892 is a reply to message #789965] Mon, 06 February 2012 11:30 Go to previous message
balachandar sivalingam is currently offline balachandar sivalingamFriend
Messages: 9
Registered: January 2012
Junior Member
Thank you for the Guidance.
Previous Topic:Uh-Oh (re: #786618)
Next Topic:2nd Y-axis not visible on deployed report
Goto Forum:
  


Current Time: Thu Mar 28 22:23:44 GMT 2024

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

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

Back to the top