Merge Multiple PDF using Apache PDFBox

Merging of multiple PDF’s can be easily done using PDFMergerUtility class of PDFBox. Lets see an example on how to Merge multiple pdf using Apache PDFBox.

The important methods that we will use of the PDFMergerUtility are:

a) addSource(String source)
Add a source file to the list of files to merge.

b) setDestinationFileName(String destination)
Set the name of the destination file

c) mergeDocuments(MemoryUsageSetting memUsageSetting)
Merge the list of source documents, saving the result in the destination file.

Example

We had already created 3 PDF’s from our previous posts, so we will use them and merge those into one pdf.

Output
You will see a new file created that has contents of all the three files.

Merge Multiple PDF using Apache PDFBox

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn