Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
access total page count after generating report.
shyasware
how to access total page count using api after generating pdf report
Find more posts tagged with
Comments
JasonW
Are you generating the pdf from a rptdocument? Meaning are you using a run task then a render task? If so you can get the page count from the rptdocument like:
IReportDocument document = null;
//Open the report design
document = engine.openReportDocument("reports/myreport.rptdocument");
long pagecnt = document.getPageCount();
Jason
shyasware
My understanding was IReportDocument object will have information enough to generate report but will not contain information regarding report to be generated from it. Am I missing something ? <br />
<br />
this is how my code looks. I am using sample customer.rptdesign that comes with birt2.6<br />
<br />
<span style='font-family: Courier New'>IReportRunnable iRptRunnabale = engine.openReportDesign("C:/workspace-birt26/customers.rptdesign");<br />
IRunTask iRunTsk = engine.createRunTask(iRptRunnabale);<br />
iRunTsk.run("C:/temp/test.rptdocument");<br />
iRunTsk.close();<br />
<br />
IReportDocument iReportDocument = engine.openReportDocument("C:/temp/test.rptdocument");<br />
IRenderTask task = engine.createRenderTask(iReportDocument);<br />
<br />
PDFRenderOption options = new PDFRenderOption();<br />
options.setOutputFileName("C:/temp/customers.pdf");<br />
<br />
task.setRenderOption(options);<br />
task.render( );<br />
long pageCount1 =iReportDocument.getPageCount();<br />
iReportDocument.close();<br />
<br />
long pageCount2=task.getPageCount() ;<br />
task.close( );<br />
engine.destroy( );<br />
Platform.shutdown();<br />
System.out.println("pageCount1 :" +pageCount1 + "..pageCount2 : " +pageCount2);</span><br />
<br />
and the output from above println is <br />
pageCount1 :1..pageCount2 : 1
JasonW
In later versions of BIRT with fixed report layout all formats should have the same number of pages. To actaully get the number of PDF pages generated you can make use of iText calls because BIRT already uses iText. For example:
PDFRenderOption options = new PDFRenderOption();
options.setOutputFileName("output/resample/topnpercent.pdf");
options.setOutputFormat("pdf");
IRenderTask rtask = engine.createRenderTask(document);
rtask.setLocale(new Locale("en", "US"));
rtask.setRenderOption(options);
rtask.render();
System.out.println(rtask.getPageCount());
rtask.close();
document.close();
engine.destroy();
PdfReader rd1 = new PdfReader( "output/resample/topnpercent.pdf" );
System.out.println( "iText " + rd1.getNumberOfPages());
rd1.close();
Make sure to import the pdf reader class:
import com.lowagie.text.pdf.PdfReader;
Jason