Home
Analytics
Print report instead of displaying
hallj05
<p>Hey, we are using the Open Source BIRT version 4.4.1 and are using the BIRT viewer.</p>
<p> </p>
<p>I'm trying to make it so that when a user clicks a button on a jsp page that it will print a report without displaying it. If it can have the choose printer window open so that the user could select the printer would be even better.</p>
<p> </p>
<p>I've read that this is possible by adding the following onto the url call for BIRT "&__action=print".</p>
<p>Although this is giving the following error: sun.print.PrintJobFlavorException: invalid flavor</p>
<p> </p>
<p> </p>
<p>Maybe another possible approach</p>
<p>Is there a way to make a report try to print on load of the report? Since I could load the report and just not display it to the user and if the report could call the print when it's done loading so that the user can select printer and then it will print.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
Clement Wong
<p>If you would like a button (please note that this is just a sample, and you can put this button wherever), put a print icon in the existing toolbar that would call a few JavaScript commands to open a new window with the PDF version and perform a window.print().</p>
<p> </p>
<p>Modify <strong>ToolbarFragment.jsp</strong> under ...\birt\webcontent\birt\pages\control</p>
<p> </p>
<p>You can find these lines where the current printer icon is:</p>
<pre class="_prettyXprint">
<TD WIDTH="6px"/>
<TD WIDTH="15px">
<INPUT TYPE="image" NAME='print' SRC="birt/images/Print.gif"
TITLE="<%= BirtResources.getHtmlMessage( "birt.viewer.toolbar.print" )%>"
ALT="<%= BirtResources.getHtmlMessage( "birt.viewer.toolbar.print" )%>" CLASS="birtviewer_clickable">
</TD></pre>
<p>Then add the following lines:</p>
<pre class="_prettyXprint">
<SCRIPT type="text/javascript">
function printReport() {
var printWindow = window.open (window.location.href.replace("__format=html","__format=pdf"));
printWindow.print();
return true;
}
</SCRIPT>
<TD WIDTH="6px"/>
<TD WIDTH="15px">
<IMG SRC="birt/images/Print.gif" onclick="javascript:printReport()" CLASS="birtviewer_clickable">
</TD> </pre>
<p>Or better yet, how does your existing application open the report to the end user? Why not call the JavaScript to run your report and view it in PDF and do the window.print() like what I have in my sample, but in your code/app?</p>
hallj05
<p>Currently the way we are viewing reports is by using the Birt viewer tag library and we display the report into a dojo contentpane. But for this report we wouldn't have space on the page to display the report so we were going to have a button on the jsp page where the user could click it and it would just print the report without displaying the report.</p>
<p> </p>
<p>Although I think that we have now decided to instead make the report display in a dialog box when the button is clicked, and then use the print button on the report viewer.</p>
<p> </p>
<p> </p>
<p>Another question sort of related to this. The print button on the report viewer. When it's clicked and the options are selected (like pdf/html) then it opens in a new window. In this new window sometimes it gives the print options window on the left and sometimes it's just a new window with the report in it and the user would have to right click and select print.</p>
<p> </p>
<p>Is there a reason as to why the print options part of the page doesn't load each time. I can add pictures of what I'm talking about if that would help.</p>
Clement Wong
<p>I'm not sure I understand. Please do include screenshots to clarify.</p>
hallj05
<p>So when we click the print button on the report then select html and all pages options and click ok. It beings up the pages shown in the two attached images.</p>
<p> </p>
<p>Sometimes it's just the report like in Print1.png, and the user will need to right click and select print to print.</p>
<p> </p>
<p>Other times it gives us the report like in Print2.png where the user can select to save or print from the options on the left.</p>
<p> </p>
<p>Note these are both from the Chrome browser. In IE it seems to only do the one like Print1.png.</p>
<p> </p>
<p>Any idea as to why the print it acting slightly different? I'd like to get them to do like Print2.png each time if possible.</p>
<p> </p>
<p>Thanks!</p>
Clement Wong
<p>So on the <em>same </em>machine running with a Chrome browser, with the same report, you see different behavior when Select Print > HTML > OK?</p>
<p> </p>
<p>The JavaScript that handles the "printing" after you click on OK is in BirtPrintReportDialog.js under org.eclipse.birt.report.viewer_4.****\birt\webcontent\birt\ajax\ui\dialog.</p>
<p> </p>
<p>You can use Chrome DevTools and add breakpoints in __printAction in BirtPrintReportDialog.js. Then you can walk through and see what a working execution path takes versus a non-working execution path. You'll notice that there is a browser check.</p>
<p> </p>
<p>My original suggestion should work for all browsers. It would be an addition or replacement to the existing Print button in the BIRT Viewer toolbar.</p>
hallj05
<p>It was the same machine, but the report was different. I'm not sure what setting on a report could make it act differently though.</p>
<p> </p>
<p>As for your original suggestion can you explain what would happen when the print button is clicked? What would it pop up showing the user? Also I'd think that we would want to print from HTML, but that looks like I would just change the replace line.</p>
Clement Wong
<p>Without looking at the two different report designs, I could not guess as to what would make it act differently.</p>
<p> </p>
<p>My original suggestion opens a new window with the report and the print dialog box appears. Please try out the suggestion to see it in effect.</p>
hallj05
<p>Sorry for the long time to respond.</p>
<p> </p>
<p>I finally got around to trying your original suggestion. The only issue is that it loses all the report parameters since they were not in the url for security reasons.</p>
<p> </p>
<p>we are passing in the parameters like this to the Birt Viewer</p>
<p><c:forEach items="${param}" var="par"><br>
<c:if test="${par.key != 'reportDesign'}"><br>
<birt:param name="${par.key}" value='${par.value}'></birt:param><br>
</c:if><br>
</c:forEach></p>
<p> </p>
<p>Is there a way that these can be used with your suggestion?</p>
Clement Wong
<p>Are you able to use session information to store the parameters in your application's architecture?</p>
<p> </p>
<p>If so, you can use this technique so that the parameters won't be lost.</p>
<p><a data-ipb='nomediaparse' href='
https://wiki.eclipse.org/Adding_an_Object_to_the_Application_Context_for_the_Viewer_(BIRT)'>https://wiki.eclipse.org/Adding_an_Object_to_the_Application_Context_for_the_Viewer_(BIRT)</a></p>
;
hallj05
<p>We could but we are trying to avoid putting things into session if at all possible and since the default print also works, although it requires an extra step or two, I think that we might just have to go that way.</p>
<p> </p>
<p>Thanks for the help though!</p>