PDF Creation with direct print dialog

Von Tobias Arnhold 9.12.2012

This solution is based on the usage of Jasper Reports to create PDF reports inside APEX.

You may had the requirement to create a PDF document with a direct print dialog but there should be no download pop-up dialog or an in-line view appear where the end user explicitly needed to click on the print button. Seems to be a simple problem: Print dialog should immediately appear after PDF creation.

Actualy there is a quite easy workaround available:
Just add this new property under the properties section (for you document) in the iReport builder settings.

/* Property name */
/* Property value */
this.print({bUI: true,bSilent: true,bShrinkToFit: false});
Now every time you create the PDF and open it. The print dialog starts automatically (at least with Adobe PDF).

Next step is to configure a way so that you do not need to open or close the PDF manually.
For that add a new HTML area with the following code on your master page (like page 1).

function refreshPDF(){
var iframe = document.getElementById('region_iframe_pdf'); 
iframe.src = 'f?p=&APP_ID.:2:&SESSION.:::2::';
<!--  iFrame element which leads to page 2 (including our Jasper Reports Call as BeforeHeader Process) -->
<iframe id="region_iframe_pdf" src="#" style="border:0px #FFFFFF none;" name="iFramePDF" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="1px" width="1px"></iframe>
Now we only need to call the javascript function to refresh our page 2 (which includes our PDF generation):
This could be added as button href link or as a dynamic action.
The generated PDF on page 2 must be an embedded PDF.
The trick is that the iFrame is more or less not visible to the end user and becomes only refreshed when the end user calls the function: refreshPDF

The idea and most of the code comes from my good fellow Sebastian.

Post Tags: