Copy a selection of pages to new PDF files : PDF Stamper « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class MainClass {

  public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("HelloWorldMultiplePages.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("HelloSelectedOdd.pdf"));
    reader.selectPages("o");
    stamper.close();
    reader = new PdfReader("HelloWorldMultiplePages.pdf");
    stamper = new PdfStamper(reader, new FileOutputStream("HelloSelectedEven.pdf"));
    reader.selectPages("e");
    stamper.close();
    reader = new PdfReader("HelloWorldMultiplePages.pdf");
    stamper = new PdfStamper(reader, new FileOutputStream("HelloSelected12379.pdf"));
    reader.selectPages("1-3, 7-9, !8");
    stamper.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