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)
In Jsapi, how can i tell if the report is being run as PDF (or otherwise)?
jshaw
<p>Hi, how can i test if a report is being run as a pdf output, or doc/xls etc, is there a parameter i can test to see? I want to adjust the width of a chart depending on it.</p>
Find more posts tagged with
Comments
Clement Wong
<p>Are you referring to the DEAPI (Design Engine) API when a report is run?</p>
<p> </p>
<p>In the Design, you can add the following code to detect the format in the <em>initialize </em>event (specifically for the Run phase because initialize is called twice, once for Run and another for Render) and save to a global variable.</p>
<pre class="_prettyXprint">
if(reportContext.getAppContext().get("JREMTask").getTaskType() == Packages.org.eclipse.birt.report.engine.api.IEngineTask.TASK_RUN){
//reportContext.getAppContext().get("JREMTask").setIsProgressive(false);
reportContext.setGlobalVariable("theFormat", reportContext.getOutputFormat());
}
</pre>
<p>So then you can use the global variable in the <em>beforeFactory </em>event to do your logic:</p>
<pre class="_prettyXprint">
// This logging only works in commercial BIRT Designer Professional
//logger = java.util.logging.Logger.getLogger("birt.report.logger");
//logger.warning ("beforeFactory
");
//logger.warning ( reportContext.getGlobalVariable("theFormat") );
if ( reportContext.getGlobalVariable("theFormat") == "html")
// do this
else
// do that</pre>
<p>The reason for calling not calling <span style="font-family:'courier new', courier, monospace;">reportContext.getOutputFormat()</span> in <em>beforeFactory </em>is because of <a data-ipb='nomediaparse' href='
https://bugs.eclipse.org/bugs/show_bug.cgi?id=331713'>this
Bugzilla entry</a>.</p>
jshaw
<p>Hi, yes thanks for that info, i want to change the size of e.g. a chart so that when it shows on the web it might be bigger than when it displays in PDF since the latter is a more constrained environment.</p>
<p> </p>
<p>I followed what you said but i have a problem in placing the code to set the size, i have tried various places but keep getting render errors. I was thinking i need something like this (where i have provided the chart with the bookmark below), but where does it go? (Birt 4.4.0)</p>
<p> </p>
<p> </p>
<p class=""><span> var</span> bchart = actuate.viewer.getCurrentPageContent( ).getChartByBookmark( <span>"TheChart"</span> );</p>
<p class=""> </p>
<p class=""><span> if</span> ( reportContext.getGlobalVariable(<span>"theFormat"</span>) == <span>"html"</span> || reportContext.getGlobalVariable(<span>"theFormat"</span>) == <span>"xhtml"</span>)</p>
<p class=""> bchart.setSize(500,500);</p>
Clement Wong
<p>Oh, I see that you're using commercial BIRT since I see actuate.viewer...</p>
<p> </p>
<p>What is your use case? How are reports being displayed? How does an end user select the report/format? Are they running a .rptdesign or viewing a .rptdocument?</p>
<p> </p>
<p>The code I was suggesting was a runtime/design change.</p>
<p> </p>
<p>If you're using JSAPI, you can resize like this:</p>
<pre class="_prettyXprint">
var chart = viewer.getCurrentPageContent( ).getChartByBookmark("TheChart");
chart.getClientChart().setSize(600, 600);</pre>
<p>Also, attached is a sample with a HTML5 chart that dynamically resizes the both the initial browser size and a manual resize of the browser window. The code is in the clientScripts > onContentUpdate.</p>
<p> </p>
<p>Why not have the .rptdesign have the chart width for PDF and then if using JSAPI or web viewer, it will resize accordingly?</p>
jshaw
<p>Hi, thanks, your example was very helpful, and is easily modified to support more charts.</p>
<p> </p>
<p>(My reports are all .rptdesign, user sees it first in the Viewer and can then select to print. The PDF sizes are in the rptdesign file and it would print just fine but come out too small in the Viewer until i applied this dynamic code)</p>