Press "Enter" to skip to content

Merge/Combine Multiple PDF Files into One PDF in Oracle Using PLPDF_TOOLKIT PL/SQL Package

In this tutorial, I am giving an example to merge/combine multiple PDF files into one PDF file in Oracle using PLPDF_TOOLKIT PL/SQL package.

Assume you have a table for employees having a BLOB field and for each employee this table containing multiple documents in PDF format and you want to merge all these documents for an employee to one document and save it to another table’s BLOB field.

You can check my previous posts to how to save PDF files into a BLOB column, below is the list:

From the above-mentioned posts, you will learn how to save single PDF and extract the BLOB data containing single PDF. Here you will learn how to combine multiple PDF files to one PDF file and store in a BLOB.

Merge/Combine Multiple PDFs into One PDF File Using PLPDF_TOOLKIT.MERGE Function

The following is the simple structure of an employee table to contain multiple PDF files (in multiple records) stored in BLOB for each employee. From this table, we will get the files to merge. For testing, create this table and insert some multiple records (PDF files) for employee number 76465:

1. Create a Source Table

Create Table Emp_Docs (
empno number,
blob_data blob

2. Create a Table to Store Merged PDF

Now create a table to store the merged PDF files for an employee:

Create Table Emp_Pdfs (
empno number,
merged_pdf blob

3. Create a PL/SQL Program to Merge PDFs

Then run the following PL/SQL code to get the PDF files for an employee 76465, merge into one PDF file and store it to Emp_Pdfs table. To perform this task, I am using PLPDF_TOOLKIT.MERGE function.


  l_Blob1 BLOB; 
  l_Blob2 BLOB; 
  l_Blob3 BLOB; 
  CURSOR Cur_empDocs IS 
    SELECT blob_data, 
           Rownum Row_n 
      FROM emp_docs 
     WHERE empno = 76465;

  n_Count   INTEGER := 0; 
  FOR c IN Cur_empDocs LOOP 
    IF c.row_n = 1 THEN 
      Dbms_Lob.Createtemporary(Lob_Loc => l_Blob1, 
                               Cache   => TRUE, 
                               Dur     => Dbms_Lob.Call); 
      l_Blob1 := c.blob_data; 
      Dbms_Lob.Createtemporary(Lob_Loc => l_Blob2, 
                               Cache   => TRUE, 
                               Dur     => Dbms_Lob.Call); 
      l_Blob2 := c.blob_data; 
      Dbms_Lob.Createtemporary(Lob_Loc => l_Blob3, 
                               Cache   => TRUE, 
                               Dur     => Dbms_Lob.Call); 
      l_Blob3 := Plpdf_Toolkit.Merge(l_Blob1, 
      l_Blob1 := l_Blob3; 
    END IF; 
    n_Count := n_Count + 1; 
  IF n_Count > 0 THEN 
    insert into emp_pdfs (empno, merged_pdf) values (76465, l_blob1);
  END IF; 

For example, if there are 3 PDF files stored in 3 records for the employee 76465, it will be combined into one PDF. Even if there is only one PDF document for an employee then it will store the only one.

You can query the table Emp_Pdfs to see the result.

See also:

Have you found the answer to your question? If not, you can discuss it with me in the comments section below or join my Q&A community for developers and ask your question. It is FREE.

Vinish Kapoor


Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Newest Most Voted
Inline Feedbacks
View all comments
Praveen Jain
Praveen Jain
6 months ago
Hi I don't find Plpdf_Toolkit package in oracle
Reply to  Vinish Kapoor
4 months ago

It is instaled and working for some files, but for some cases, this is the error that is getting when merging
two files

4 months ago

can you please help me with this issue? I am using plpdf_toolkit.merge in my procedure, but I got the error:
ORA-20000: Could not push back 180308 bytes in order to reparse stream. Try increasing push back buffer using system property com.plpdf.baseParser.pushBackSize
at com.plpdf.pdfparser.BaseParser.parseOMStream(
at com.plpdf.pdfparser.PDFParser.parseObject(
at com.plpdf.pdfparser.PDFParser.parse(
at com.plpdf.smmodel.SMDocument.load(
at com.plpdf.smmodel.SMDocument.load(
at com.plpdf.toolkit.PDFMerger.merge(
at com.plpdf.PlpdfToolkit.merge(
ORA-06512: in “PLPDF.PLPDF_TOOLKIT”, regel 68
ORA-06512: in “PLPDF.PLPDF_TOOLKIT”, regel 910