Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Import page

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();   } }