Class PageExtractor


  • public class PageExtractor
    extends Object
    This class will extract one or more sequential pages and create a new document.
    • 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 (1-based, inclusive)
        endPage - The last page you want extracted (1-based, inclusive)
    • Method Detail

      • extract

        public PDDocument extract()
                           throws 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:
        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