PDFBox Removing Pages - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
PDFBox Removing Pages

PDFBox Removing Pages

PDFBox Removing Pages

We can remove pages from existing PDF document. removePage() method of the PDDocument class is used to remove the page from the document.
Follow the steps below to remove page from the existing PDF document-

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

   }
}

About Mariano

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.