#47 Oracle APEX download PDF reports

Hi all,

A while ago a customer asked me if it is possible to download a (classic) report as PDF file. I know that the interactive report has a option to download it as PDF, but the classic report hasn't that option. So I've searched on the internet for a JS library that has the ability to download a PDF.

I've found the open source library jsPDF and the addon Autotables. JsPDF is a very nicefull tool HTML5 client side solution for download PDF. The addon Autotables is used for generating reports in JsPDF using JSON (AJAX call).

 How to use it in APEX:
  1. Download the source code or use file URL's.
  2. Create a AJAX callback procedure that returns JSON data. (Note: Array or object type will both work)
  3. Implement some Javascript code.
  4. function download_pdf(){
     var doc      = new jsPDF('landscape', 'pt'); //Create JSPDF
     var columns  = ["EMPNO", "ENAME"];           //Report headers
     var filename = 'Download PDF';               //filename
    
     // Load data into report
     apex.server.process ( "DOWNLOAD_PDF", {}, {
        success: function(Data) 
            { 
               doc.autoTable(columns, Data); //Combine headers with data
               doc.save(filename);           //Create PDF
            }
        });
    }
  5. Create a dynamic action that will fire the Javascript code when the user click on the download button.
Report in APEX


Report in PDF file


Demo: https://apex.oracle.com/pls/apex/f?p=94735:20

11-12-2018: I have created a APEX plugin for this. Check it on https://apex.world/ords/f?p=100:710:5668685349080::::P710_PLG_ID:S4S_PDF_DOWNLOAD

It is also possible to customize the report, like changing header colors, fontsize, etc. For more info visit the Github page.

See you next time!

Comments

Popular posts from this blog

#38 Oracle apex static height region

#43 Add color to selected tab Oracle APEX

#19 Clear cache in a PL/SQL process in Oracle APEX