Home
Analytics
Detecting web viewer in report
sschafer2
I recently discovered that when a report is directed to the AJAX web viewer, the reportContext.getOutputFormat() returns "pdf". At first I was surprised but then I realized it makes sense. But now I have a problem: I want highlight rules that change background colors, etc when the report is REALLY going to PDF and not the web viewer. This is because the web viewer is on-screen and a PDF could potentially be printed. Anyone have any ideas how this could be accomplished?
Find more posts tagged with
Comments
johnw
reportContext.getOutputFormat() is always returning PDF in the webviewer? What version of BIRT is this in? (p.s. is this Steve?)
sschafer2
Hi John, yes this is Steve. It's BIRT 2.6.2 (on Linux) and I am examining reportContext.getOutputFormat() in a highlight script on a table row because I want to eliminate the background color when the report is being printed to save ink. The reason I say it makes sense is because the web viewer behaves exactly like PDF. It has the same table of contents, is pagenated, etc.
mcremer
<blockquote class='ipsBlockquote' data-author="'sschafer2'" data-cid="83643" data-time="1317472815" data-date="01 October 2011 - 05:40 AM"><p>
Hi John, yes this is Steve. It's BIRT 2.6.2 (on Linux) and I am examining reportContext.getOutputFormat() in a highlight script on a table row because I want to eliminate the background color when the report is being printed to save ink. The reason I say it makes sense is because the web viewer behaves exactly like PDF. It has the same table of contents, is pagenated, etc.<br /></p></blockquote>
<br />
Hi Steve we seem to have the same problem when we run this script:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (reportContext.getOutputFormat() == "pdf"){
this.getStyle().pageBreakAfter = "always";
}
else{
this.getStyle().pageBreakAfter = "auto";
}
</pre>
<br />
We want that in a pdf the page break is on on the end of a table and in the webviewer not. But it seems the webviewer is also listed as output format pdf this of course is a problem. We are using Eclipse BIRT 2.6.0 in our project.
CBR
Hi,
please have a look at the BIRT event model. When running in BIRT WebViewer using the frameset mapping (two phases) it first generates a .rptdocument. This file does not depend on the output format so when generating the rptdocument the BIRT report engine doesn't know about the output format (this is what you describe as: Has always value PDF). In this phase the onPrepare and onCreate events are evaluated. That means that if you check the output format in onCreate or onPrepare it just gives you some value (but not the real output format because it simply doesn't know about it).
After generating the .rptdocument this file is rendered to the desired output format using the second phase. The second phase is a separate process that doesn't know anything about the first phase. In that phase the BIRT engine knows about the concrete output format which means that you can check the value of it and always getting back some meaningful value. In that phase all onRender events are processed.
The issue you are seeing is not related to the BIRT WebViewer but to the Event Model itself. Your report won't work in any application that is using the two phases instead of the combined single phase model (this combined model evaluated onCreate, onPrepare and onRender just one after the other and the concrete output format is known before the any expression in the report is evaluated).
Conclusion:
If you are using events to do something in dependence of the output format always use the onRender event of a report item. When using onPrepare or onCreate instead it will only work if you are using the single phases model. The single phases model is used by the run servlet and in the BIRT Designer report preview.
johnw
Steve,
Take a look at the following example. It is removing a hyperlink when in PDF, but the concept is the same. You would be changing the elements style at that point since it is the only thing that is accessible during the onRender phase.
I'll ping you in a bit to discuss further.
John
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="
http://www.eclipse.org/birt/2005/design"
; version="3.2.22" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.6.2.r262_v20110209 Build <2.6.2.v20110219-1842></property>
<property name="units">in</property>
<method name="initialize"><![CDATA[//We only want to add this into our code when the value is not null for the parameter sort
/*
if ( params["rptprmSortOrder"].value != null ) {
//Bring in the BIRT Report Model API and for CONSTANTS
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element ); //Create a dynamic sort condition
var sortCondition = StructureScriptAPIFactory.createSortCondition();
//Based on the value of the sort parameter, set the appropriate key value for sorting
switch (params["rptprmSortOrder"].value) {
//Remember that for the key, we need to use the fully qualified row and field name as a string, not as a value
case "date" :
sortCondition.setKey("row[\"PAYMENTDATE\"]");
break;
case "price" :
sortCondition.setKey("row[\"AMOUNT\"]");
break;
}
//set condition to ascending order
sortCondition.setDirection("asc");
//Add to the table
this.addSortCondition(sortCondition);
}
*/]]></method>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="layoutPreference">auto layout</property>
<property name="bidiLayoutOrientation">ltr</property>
<styles>
<style name="report" id="4">
<property name="fontFamily">"Verdana"</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="topMargin">0.25in</property>
<property name="leftMargin">0.25in</property>
<property name="bottomMargin">0.25in</property>
<property name="rightMargin">0.25in</property>
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<label id="7">
<property name="newHandlerOnEachEvent">true</property>
<method name="onRender"><![CDATA[if (reportContext.getOutputFormat().equalsIgnoreCase("PDF"))
{
this.setAction(null);
}
]]></method>
<text-property name="text">Test</text-property>
<list-property name="action">
<structure>
<property name="linkType">hyperlink</property>
<expression name="uri">"
http://www.google.com"</expression>
;
<property name="targetWindow">_blank</property>
</structure>
</list-property>
</label>
</body>
</report>
ashley.owens
<p>I tried adding the "__format" parameter (setting it to "pdf"), and I also followed the example of an OOB Maximo report and put the SQL in beforeClose() with condition
if(reportContext.getOutputFormat() != "pdf")</p><p>I also tried setting reportContext.getOutputFormat() to a global variable in beforeFactory() and use that to determine whether SQL should be executed.
</p><p>Unfortunately, the report SQL still executed a 2nd time when exporting (to PDF, for example).
Has anyone been able to successfully set a report to execute SQL only once, or to NOT execute SQL when it's exported? Thank you so much for any advice!</p>
ashley.owens
<p>UPDATE: After talking with IBM, we decided to set the reports that update data as "Schedule Only" within Report Administration, forcing the user to schedule the report for a future date and email it to themselves (the "Immediate" option is gone from the dialog if "Schedule Only").</p>