Read Existing PDF In Java

Chapter: iText Last Updated: 14-08-2016 18:25:07 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;

public class JavaiTextReadExisting {

	private static String INPUTFILE = "c:/temp/FirstPdf.pdf";
	private static String OUTPUTFILE = "c:/temp/ReadPdf.pdf";

	public static void main(String[] args) throws DocumentException, IOException {
		Document document = new Document();

		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE));
		document.open();
		PdfReader reader = new PdfReader(INPUTFILE);
		int n = reader.getNumberOfPages();
		PdfImportedPage page;
		// Go through all pages
		for (int i = 1; i <= n; i++) {
			// only page number 2 will be included
			if (i == 2) {
				page = writer.getImportedPage(reader, i);
				Image instance = Image.getInstance(page);
				document.add(instance);
			}
		}
		document.close();

	}
}
                /* ............... END ............... */
        

Tags

Read Existing PDF , iText, Java

Similar Programs Chapter Last Updated
Java Set Background To Table Example iText 22-07-2017
Java PDF Hello World Example iText 14-08-2016
Java PDF Formatting Using iText iText 14-08-2016
Read OR Modify PDF File In Java Using iText iText 12-08-2016
PDF With Limited Permissions In Java Using iText iText 12-08-2016
Password Protected PDF Files Using Java iText iText 12-08-2016
Styling Or Formatting PDF In Java Using iText iText 11-08-2016
Create Lists In PDF Using Java iText iText 10-08-2016
Create Tables In PDF Using Java iText iText 10-08-2016
Add Images To PDF In Java Using iText iText 10-08-2016
File Attributes To PDF In Java Using iText iText 10-08-2016
PDF Creation In Java Using iText iText 10-08-2016

1