Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;

public class RemovingPages {

   public static void main(String args[]) throws IOException {

      //Loading an existing document
      File file = new File("C:/PdfBox_Examples/sample.pdf");
      PDDocument document = PDDocument. load (file);
       
      //Listing the number of existing pages
      int noOfPages= document.getNumberOfPages();
      System.out.print(noOfPages);
       
      //Removing the pages
      document.removePage(2);
      
      System.out.println("page removed");

      //Saving the document
      document.save("C:/PdfBox_Examples/sample.pdf");

      //Closing the document
      document.close();

   }
}
Source by coderlessons.com #
 
PREVIOUS NEXT
Tagged: #java
ADD COMMENT
Topic
Name
8+9 =