• Leistungsspektrum
    Die passenden Lösungen für Ihre Anforderungen.
    Mehr Details unter der Rubrik: Leistungen
  • Professionelle Anwendungen
    Holen Sie mehr aus Ihren APEX Applikationen heraus.
  • Neueste Designs
    Nutzung von erweiterten Web 2.0 Möglichkeiten und Entwicklung von Corporate Designs
  • Individuelle Lösungen
    Entwicklung von Business-Anwendungen genau nach Ihren Wünschen.
  • Upgrade Lösungen
    Weiterentwicklung bestehender Anwendungen.
  • Schulungen und Vorträge
    Die passenden Schulungen genau für Sie zugeschnitten. Beispiel: Navigationsbeispiele
  • Plugins und Third Party Erweiterungen
    Erweitern Sie die Funktionalität ihrer Anwendungen mit einem modularen Entwicklungsansatz.

12 September, 2012

PDF Creation with direct print dialog


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 */
net.sf.jasperreports.export.pdf.javascript
/* 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).

<script>
function refreshPDF(){
var iframe = document.getElementById('region_iframe_pdf'); 
iframe.src = 'f?p=&APP_ID.:2:&SESSION.:::2::';
};
</script>
<!--  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):
javscript:refreshPDF()
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.

No comments: