Sunday, April 19, 2009

Combine two pdf files using itext

Here is a simple way to combine two pdf files into one.
I have used iText-2.1.5.jar

This is the sample code

import java.io.FileOutputStream;

import com.lowagie.text.pdf.PdfCopyFields;

import com.lowagie.text.pdf.PdfReader;

public class PDFTest {

public static void main(String[] args) throws Exception {

System.out.println("Concatenate Two PDF");

PdfReader reader1 = new PdfReader("D:/upload/first.pdf");

PdfReader reader2 = new PdfReader("D:/upload/second.pdf");

PdfCopyFields copy = new PdfCopyFields(new FileOutputStream("D:/upload/concatenatedPDF.pdf"));

copy.addDocument(reader1);

copy.addDocument(reader2);

copy.close();

}

}

No comments:

Post a Comment