Class PageExtractor


  • public class PageExtractor
    extends java.lang.Object
    This class will extract one or more sequential pages and create a new document.
    • Constructor Summary

      Constructors 
      Constructor Description
      PageExtractor​(PDDocument sourceDocument)
      Creates a new instance of PageExtractor
      PageExtractor​(PDDocument sourceDocument, int startPage, int endPage)
      Creates a new instance of PageExtractor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      PDDocument extract()
      This will take a document and extract the desired pages into a new document.
      int getEndPage()
      Gets the last page number (inclusive) to be extracted.
      int getStartPage()
      Gets the first page number to be extracted.
      void setEndPage​(int endPage)
      Sets the last page number to be extracted.
      void setStartPage​(int startPage)
      Sets the first page number to be extracted.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sourceDocument

        private PDDocument sourceDocument
      • startPage

        private int startPage
      • endPage

        private int endPage
    • Constructor Detail

      • PageExtractor

        public PageExtractor​(PDDocument sourceDocument)
        Creates a new instance of PageExtractor
        Parameters:
        sourceDocument - The document to split.
      • PageExtractor

        public PageExtractor​(PDDocument sourceDocument,
                             int startPage,
                             int endPage)
        Creates a new instance of PageExtractor
        Parameters:
        sourceDocument - The document to split.
        startPage - The first page you want extracted (inclusive)
        endPage - The last page you want extracted (inclusive)
    • Method Detail

      • extract

        public PDDocument extract()
                           throws java.io.IOException
        This will take a document and extract the desired pages into a new document. Both startPage and endPage are included in the extracted document. If the endPage is greater than the number of pages in the source document, it will go to the end of the document. If startPage is less than 1, it'll start with page 1. If startPage is greater than endPage or greater than the number of pages in the source document, a blank document will be returned.
        Returns:
        The extracted document
        Throws:
        java.io.IOException - If there is an IOError
      • getStartPage

        public int getStartPage()
        Gets the first page number to be extracted.
        Returns:
        the first page number which should be extracted
      • setStartPage

        public void setStartPage​(int startPage)
        Sets the first page number to be extracted.
        Parameters:
        startPage - the first page number which should be extracted
      • getEndPage

        public int getEndPage()
        Gets the last page number (inclusive) to be extracted.
        Returns:
        the last page number which should be extracted
      • setEndPage

        public void setEndPage​(int endPage)
        Sets the last page number to be extracted.
        Parameters:
        endPage - the last page number which should be extracted