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

PDF Merge in Java (Tutorial)

2 min read

Read PDF in Java with JPedal

Introduction

Java developers working with PDF documents are always looking to enhance functionality in their document workflows.

There is a large selection of Java PDF SDK libraries for them to choose from, one of the key feature is PDF merging.

PDF merging is an important requirement for use cases such as streamlining user downloads, consolidating reports and automate back-office processes to name a few. Though most Java libraries have the feature, the ease of use can vary.

JPedal’s Merging Feature

In the latest JPedal release, we added the feature preview for merging PDF files together. We have a JPedal docs page explaining how to merge multiple PDF files into one from the Command line or Java, with options to interleave pages, add dividing pages, add footers, and normalise page size and rotation.

We are still developing this feature, so the API is subject to change, but today I am going to show you how it works.

 

Merge two PDF files using Java

Here’s a simple example demonstrating how to merge two PDF files using JPedal’s API:

Merge two PDF files using the command line

You can also merge PDF files using Java straight from the command line.

java -cp jpedal.jar org.jpedal.tools.PdfMerge inputFile1.pdf inputFile2.pdf outputFile.pdf

Interleave pages when merging PDF files in Java

The interleave option merges pages one at a time from each file, instead of adding all pages from one file before moving to the next.


Add a dividing page between merged files

This option adds a blank page between each input file, matching the size of the page before it. Note it doesn’t apply if interleave is also selected

Add a footer to merged pages

You can print the original filename and page number below the content of every page.

Normalise page size and rotation

PdfMerge can resize and rotate every page to match the first page of the first document. This is particularly useful when merging files with mixed page sizes or orientations.

Please let us know if you have any feedback about this feature preview!

Conclusion

As shown above, JPedal’s new merge feature provides a straightforward way to combine PDF files-either through a concise Java API or directly from the command line.

If you have any questions, you can view the full documentation for the PDF merging feature. You can also read from our extensive repository of posts to learn more about the PDF format.



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


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