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)
Generating PDF
zac
Hello,<br />
I'd like to generate a pdf via JavaScript. I'm using BIRT 2.5.2. I've added the following code in the report "beforeRender" event but the atttributeBean value is always null. What am I doing wrong?<br />
Also <br />
Thanks for your help!<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage(Packages.org.eclipse.birt.report.engine.api);
//attributeBean is a Birt Viewer supplied session variable
var request = reportContext.getHttpServletRequest();
if (request) {
var attributeBean = request.getAttribute('attributeBean');
if (attributeBean && !attributeBean.isDesigner()) {
var reportDoc = attributeBean.getReportDocumentName();
var re = reportContext.getReportRunnable().getReportEngine();
var doc = re.openReportDocument(reportDoc);
var options = new PDFRenderOption();
var outputfile = 'c:/report.pdf';
options.setOutputFileName(outputfile);
options.setOutputFormat('pdf');
ntask = re.createRenderTask(doc);
ntask.setRenderOption(options);
ntask.render();
doc.close();
ntask.close();
}
}</pre>
Find more posts tagged with
Comments
kclark
You might try running eclipsec.exe from cmd, assuming your in Windows. This will give you output to the console. If you get any errors here when running your report could you post them?
zac
Thanks for your reply. I got it working by using the event "afterRender"
rajani_interwove
<p><sub class='bbc'>I am getting null value for "afterRender" event too. Can you please share an example.</sub></p><p> </p><p><sub class='bbc'>-Rajani</sub></p>
kclark
<p>Hi rajanig, can you post your code please?</p>
rajani_interwove
<p>Please find attached my test report design.</p><p> </p><p>-Rajani</p>
kclark
<p>Are you testing this in the designer or deployed? I'm not having any problems with this code</p><pre class="_prettyXprint">importPackage(Packages.org.eclipse.birt.report.engine.api);Packages.java.lang.System.out.println("************TEST*************");var request = reportContext.getHttpServletRequest();Packages.java.lang.System.out.println(request);if(request) { var attributeBean = request.getAttribute('attributeBean'); Packages.java.lang.System.out.println(attributeBean); Packages.java.lang.System.out.println(attributeBean.isDesigner()); if (attributeBean && !attributeBean.isDesigner()) { Packages.java.lang.System.out.println("TRUE"); var reportDoc = attributeBean.getReportDocumentName(); var re = reportContext.getReportRunnable().getReportEngine(); var doc = re.openReportDocument(reportDoc); var options = new PDFRenderOption(); var outputfile = 'c:/Test/report.pdf'; options.setOutputFileName(outputfile); options.setOutputFormat('pdf'); ntask = re.createRenderTask(doc); ntask.setRenderOption(options); ntask.render(); doc.close(); ntask.close(); }}Packages.java.lang.System.out.println("************TEST*************");</pre><p>I added the System.out.println() for debugging for when I run eclipsec.exe. Can you try using this code in eclipsec.exe and change</p><pre class="_prettyXprint">if (attributeBean && !attributeBean.isDesigner()) {</pre><p>to</p><pre class="_prettyXprint">if (attributeBean && attributeBean.isDesigner()) {</pre><p>And tell me if this works or not?</p>
rajani_interwove
<p>Thank you for your response.</p><p> </p><p>I tried the above code both in designer and on iServer. But still I am getting errors.</p><p>Here is the error on iServer :</p><p> </p><p> </p><p><span>There is non-fatal error. Cause : There are errors evaluating script "importPackage(Packages.org.eclipse.birt.report.engine.api); Packages.java.lang.System.out.println("************TEST*************"); var request = reportContext.getHttpServletRequest(); Packages.java.lang.System.out.println(request); if(request) { var attributeBean = request.getAttribute('attributeBean'); Packages.java.lang.System.out.println(attributeBean); Packages.java.lang.System.out.println(attributeBean.isDesigner()); if (attributeBean && !attributeBean.isDesigner()) { Packages.java.lang.System.out.println("TRUE"); var reportDoc = attributeBean.getReportDocumentName(); var re = reportContext.getReportRunnable().getReportEngine(); var doc = re.openReportDocument(reportDoc); var options = new PDFRenderOption(); var outputfile = 'c:/Test/report.pdf'; options.setOutputFileName(outputfile); options.setOutputFormat('pdf'); ntask = re.createRenderTask(doc); ntask.setRenderOption(options); ntask.render(); doc.close(); ntask.close(); } } Packages.java.lang.System.out.println("************TEST*************");": The choice of Java constructor println matching JavaScript argument types (null) is ambiguous; candidate constructors are: void println(char[]) void println(java.lang.String) void println(java.lang.Object) (/report/method[
@name="
;afterRender"]#5) (Element ID:1)</span></p><p> </p><p><span>My BIRT version is 3.2.23</span></p><p><span>I dont understand where I am going wrong.</span></p>
kclark
<p>Can you attach your rptdesign? I tested this code in 2.6-4.3 and it worked. I also tested this in the designer and in Tomcat 7 on Linux and Windows.</p>