Users of the open source library, iText, can merge several PDF documents into a single file. You can go online to find sample source code to use as a guide when writing your own code. The process below was developed by Web programmer Viral Patel. With iText, users can also perform various other tasks, including filling out forms and transferring pages from one PDF file to another.
- Skill level:
Use the code to create a list of InputStream from the all the input PDFs. This should be done in main() method. Call MergePDF.concatPDFs() static method for a list of input PDFs and OutputStream object for the merged output PDF. A boolean flag represents the inclusion of page numbers as page line arguments.
Convert the list of InputStream objects to a list of PDFReader objects using the concatPDFs() method, for each input PDF, while also creating a list of InputStream. Then, create a document object for the merged PDF.
Create a PDFWriter for the desired OutputStream. Additionally, you can add page numbers to your document, and the font these numbers will be written in, using BaseFont.createFont() method. Write the merged PDF file using the Document class object and PdfWriter.getInstance() method.
Write the individual pages to the merged PDF output, then add text at the bottom of the page. Finally, close all streams and clear the buffers.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for