iText in Action: Chapter 6: Working with existing PDFs


If you compile and execute this example, you'll get the following result:

You can download the full source code of ConcatenateForms1, or read it here:

 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to:
 * This example only works with the AGPL version of iText.
package part2.chapter06;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopyFields;
import com.itextpdf.text.pdf.PdfReader;
public class ConcatenateForms1 {
    /** The original PDF file. */
    public static final String DATASHEET
        = "resources/pdfs/datasheet.pdf";
    /** The resulting PDF file. */
    public static final String RESULT
        = "results/part2/chapter06/concatenated_forms1.pdf";
     * Main method.
     * @param args no arguments needed
     * @throws DocumentException 
     * @throws IOException
    public static void main(String[] args)
        throws IOException, DocumentException {
    	// Create a PdfCopyFields object
        PdfCopyFields copy
            = new PdfCopyFields(new FileOutputStream(RESULT));
        // add a document
        PdfReader reader1 = new PdfReader(DATASHEET);
        // add a document
        PdfReader reader2 = new PdfReader(DATASHEET);
        // close the PdfCopyFields object
Powered by GeSHi

The ConcatenateForms1 example is part of the book iText in Action (ISBN 9781935182610).

It's a small standalone application. You can use this example for inspiration, but please read the book if there's something you don't understand about the example. You'll find more info in Chapter 6.

Keywords for this example: AcroForm technology, Existing PDFs, Forms, PdfCopyFields, PdfReader, Concatenate PDFs > concatenate forms

If you want this example to work, you need the following jars: iText.jar

This example uses the following resources: datasheet.pdf.