Import page : PDF Stamper « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfReader;

public class MainClass {

  public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("HelloWorldMultiplePages.pdf");
    reader.selectPages("o");
    int pages = reader.getNumberOfPages();
    Document document = new Document();
    PdfCopy copy = new PdfCopy(document, new FileOutputStream("HelloWorldSelectPagesOdd.pdf"));
    document.open();
    for (int i = 0; i < pages;) {
      ++i;
      copy.addPage(copy.getImportedPage(reader, i));
    }
    document.close();

  }

}








29.3.PDF Stamper
29.3.1.Stamping PDF file
29.3.2.Import page
29.3.3.Copy a selection of pages to new PDF files
29.3.4.Create PdfImportedPage