Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside work, he’s a 1900‑rated chess player, guitarist, and French learner.

How to interleave merge PDFs in Java (Tutorial)

50 sec read

merge pdf files

We recently released a new version of our Java PDF library JPedal, which allows developers to merge PDF files using interleaving. Download a JPedal trial jar to try it out!

What is interleaving?

To interleave two or more PDF files means to combine them into a single document where the output file contains alternating pages from each input file.

For example, say you have document A with 4 pages, and document B with 5 pages. The result would look like: A1, B1, A2, B2, A3, B3, A4, B4, B5.

One example of when you might want to use this would be merging multiple copies of the same form with different answers filled in. Using an interleave merge here would make it a lot easier to compare the different answers.

How to merge with interleaving in Java

Once you have downloaded a JPedal jar, and added it to your Java project, you can use the following lines of code:

Download JPedal now

You may download a trial copy of JPedal to get familiar with how it works.

Learn more

Learn more about the PDF Merge API.

We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!



The JPedal PDF library allows you to solve these problems in Java


Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside work, he’s a 1900‑rated chess player, guitarist, and French learner.