Monday, October 12, 2009

How to integrate PL_FPDF with Apex

In my previous post about the free PL_FPDF package that allows you to produce PDF documents from PL/SQL, there was a comment asking for a step-by-step guide on how to integrate this with Oracle Application Express (Apex).

This is really quite simple. By default, the pl_fpdf.output procedure will "print" your PDF document to the web browser along with a header that instructs the browser that this is a downloadable document. All you need to do is to call your procedure that generates the PDF document from a page process within Apex.

Here are the steps:

1. Start by compiling the demo procedure from my previous post into the parsing schema of your Apex application.

2. In Apex, go to your application and add a new, blank page. Let's assume the new page number is 4.

3. Under the "Page Rendering" section, add a new Process of type "PL/SQL". The name of the process can be anything, but let's call it "Produce PDF". Make sure that the point is "On load - before header".

4. In the process source, add the following PL/SQL code:

begin
-- call the procedure to generate the PDF document and send it to the browser
test_pl_fpdf;
-- stop the Apex engine from running the rest of the page
apex_application.g_unrecoverable_error := true;
end;

5. Add a link to the new page (page number 4 if you follow my assumption in step 2) from any other page in the application.

6. Run the application. Now, whenever you navigate to page 4 the PDF file will be downloaded to the browser.

That's all you need to integrate PDF generation into your Apex application.

Hi Morthen, this is Eduardo, I work for Oracle on APEX projects, this is really what I was looking for. I was wondering if you could help me. I need to merge (after some manipulation) two or more pdf's within APEX using PLSQL. Is it possible to od it with this library? or perhaps by reading the content and then generating a single pdf instance with all the pdf's appended or merged into one single output?

Good Tutorial, really good, its very easy to implement after reading your post. Just one question for you, I am having one requirement where I need to add chart into the pdf, and that's also dynamically generated from database data. Is this possible with this package?

i downloaded the pdf_builder_pkg, and it works nice. However, when i call the ref2cursor procedure and i use a sum function in the query, the column with the sum query is not printed out on the pdf. Have you run into this?

About Me

I have been working as a consultant and software developer for 18 years (since 1997), with a special passion for relational databases. I have done a fair share of work using Microsoft tools (including SQL Server, VB, ASP, .NET and C#) and other tools (most notably Delphi), but my favorite tool is the Oracle database with PL/SQL and Apex.