Introduction: How to Merge PDF Documents
As a college student, I have found myself needing a program to combine a series of PDF documents from various assignments into a singular file to submit for a final assignment. I foresee the need for this type of program beyond my academic life, and as such, I decided to write my own program to accomplish this task. Some existing methods require you to upload your potentially sensitive documents online to merge, and others charge you to perform this merging operation. Writing my own program promises free and unlimited usage, hence its favorability.
This Instructable will be divided into two sections - the first section will provide the layman with my completed program and instructions for use, and the second section will be a guide for others looking to write their own program for the task.
My program uses the Apache PDFBox java library to accomplish the task of merging PDF documents. A big thanks goes out to that team for developing such a great tool!
Step 1: System Requirements
The operating system I use is Windows 7, and I lack the needed experience with Mac and Linux systems to evaluate whether this program will work on those systems. For Mac OS X, I would recommend this discussion if you are having problems. The program should work with Windows 8 and Windows 10 computers.
The sole requirement for this program to operate is ensuring your computer has Java up-to-date. You can update your java software here. At a minimum, you should have Java 8 installed on your computer.
In Windows 7, to check your installed version of Java, go to the Windows Start Menu and search "Java Control Panel." Click the link as shown in the second picture above. After the Java Control Panel loads, click the "About" button as shown in the third image. You will see your Java details as in the fourth image.
Step 2: Download the JAR File
At the end of this step you will find a file titled "PDFMerger." Download this file and save it in a location where you can conveniently access it. This file is a JAR file, or Java Archive file - when Java is properly installed on your system, you can double click on this file just as any other program on your computer to open it.
At some point during the download process, your computer may prompt you with a message asking if you trust the file you're downloading - this happens because some people make malicious JAR files that can harm your computer. The same message is often prompted when you download many other runnable programs from the internet. Accept the download to complete this step.
Step 3: Opening the File / Program Walkthrough
After you download the JAR file to the desired location, the next step is to run the file. Double-clicking on the PDFMerger JAR file to open it will likely cause a prompt as shown in the first picture to open. This is natural for any program downloaded from the internet, and deselecting the "Always ask before opening this file" will prevent you from being prompted again.
When the program first loads up, you will see the screen as shown in the second picture above. The following are the steps to take to merge your files:
- Click "Add to List" and navigate the file chooser that pops up (third image above) to locate the files you want to merge. Unfortunately, at this time, you can only add one file at a time to the list.
- If a file is added in error, select the file from the list and click "Remove from List."
- The order of the documents in the output file is the same as the order of the files in the list (top to bottom). You can reorder the files by selecting the desired file and using the arrow buttons.
- Set the output folder where you want the combined file to be located by using the "Set Output Folder" button and navigating the the desired folder using the folder chooser that pops up.
- In the text field, type the desired name of the output file. If you accidentally include ".pdf," there's no problem, as the program will automatically disregard it.
- If you want to delete the original files at the same time, deselect the "Keep Original File(s)" check box.
- Once you are ready, click the "Merge!" button and the file will be created, placed in the desired folder, and automatically opened for you to view.
And that's it for the first section! I hope you all find use for this tool!
For all you programmers out there, keep reading...
Step 4: Using Apache PDFBox
The reason I chose the Apache PDFBox library is owed to their PDFMergerUtility class. The documentation for this class is found here. After glancing at the java docs, I'm sure you would agree with my choice. Merging a PDF document with this class is as simple as creating an instance of PDFMergerUtility, adding a file by calling the addSource method for all PDF documents you want to add, setting the output file name by calling the setDestinationFileName method, and finally calling the mergeDocuments() method.
At the end of this step, you will find my source code for this program. You will see that 99% of the program is the GUI setup and logic, and the remaining 1% is performing the above operations.
As a programming exercise, I would recommend writing a comparable program to this one, as I found it enjoyable!
Step 5: Enjoy!
Please leave a message in the comments if you have found this program useful or if you need any help. I would appreciate any feedback!
Also, if you find any bugs, please let me know!
We have a be nice policy.
Please be positive and constructive.