Skip to Content

Merging PDF files using Java APIs

Merging PDF files using Java APIs: 

There are couple of threads and blogs in SDN which talks and assists users about creating, reading, editing the PDF (Portable Document Format) documents using Java libraries.


There will be some business specific scenarios where the applications needed merging the existing PDF files to make it as a single document. I’ve worked on one such requirement to merge more than one Insurance Forms (PDF files) which is based on couple of specific parameters. But we didn’t use the Java APIs to get it done, the client has provided us a utility developed in VB (DLL libraries) for which we had to use JNI and got the job done.


If this can be done in VB it of course can also be done in Java. Java has got a wide range of support to interact with PDF documents.


The following are some of popular Java libraries available for create/read/write PDF files:

Adobe Acrobat Reader for Java:

Read and display PDF documents. A viewer application and a JavaBean are available. Works with Java 1.1.8+. [Freeware]



A product from Lowagie to write PDF documents. Requires over Java 1.2. There’s a book iText in Action by the library’s author, Bruno Lowagie. [LGPL] jPDF:

A server-side API to publish, serve and handle PDF/FPF documents. [Commercial]


A Java class library for parsing PDF documents including PDF to text extraction, merge PDF documents, PDF document decryption. [Open source]


Java Bean to display PDF documents. [Commercial] 

This blog talks about the use of iText library to Merge Multiple PDF documents. Here is a sample code contains a method that will take a list of PDF files as input, along with an OutputStream to which the merged PDF file will be written.  

The following is the complete source code for merging more than PDF documents: 

The above code also implements paging, i.e. along with merging the PDF files the merged PDF file also ‘adds page numbers’ at the end of each page in generated PDF file.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.