How to Merge PDF Files in iText

Written by marlon trotsky
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Merge PDF Files in iText
iText allows you to merge several PDFs into one. (Alistair Berg/Digital Vision/Getty Images)

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:
Easy

Other People Are Reading

Instructions

  1. 1

    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.

  2. 2

    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.

  3. 3

    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.

  4. 4

    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.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.