Class PdfSplitter


  • public class PdfSplitter
    extends java.lang.Object
    Helper class to split the document based on some condition.
    • Field Detail

      • preserveTagged

        private boolean preserveTagged
      • preserveOutlines

        private boolean preserveOutlines
    • Constructor Detail

      • PdfSplitter

        public PdfSplitter​(PdfDocument pdfDocument)
        Creates a new instance of PdfSplitter class.
        Parameters:
        pdfDocument - the document to be split.
    • Method Detail

      • setEventCountingMetaInfo

        public void setEventCountingMetaInfo​(IMetaInfo metaInfo)
        Sets the IMetaInfo that will be used during PdfDocument creation.
        Parameters:
        metaInfo - meta info to set
      • setPreserveTagged

        public void setPreserveTagged​(boolean preserveTagged)
        If original document is tagged, then by default all resultant document will also be tagged. This could be changed with this flag - if set to false, resultant documents will be not tagged, even if original document is tagged.
        Parameters:
        preserveTagged - defines whether the resultant documents need to be tagged
      • setPreserveOutlines

        public void setPreserveOutlines​(boolean preserveOutlines)
        If original document has outlines, then by default all resultant document will also have outlines. This could be changed with this flag - if set to false, resultant documents won't contain outlines, even if original document had them.
        Parameters:
        preserveOutlines - defines whether the resultant documents will preserve outlines or not
      • splitBySize

        public java.util.List<PdfDocument> splitBySize​(long size)
        Splits the document basing on the given size specified in bytes.
        Parameters:
        size - Preferred size specified in bytes for splitting.
        Returns:
        The documents which the source document was split into. Be warned that these documents are not closed.
      • splitByPageNumbers

        public void splitByPageNumbers​(java.util.List<java.lang.Integer> pageNumbers,
                                       PdfSplitter.IDocumentReadyListener documentReady)
        Splits the document by page numbers.
        Parameters:
        pageNumbers - the numbers of pages from which another document is to be started. If the first element is not 1, then 1 is implied (i.e. the first split document will start from page 1 in any case).
        documentReady - the event listener which is called when another document is ready. You can close this document in this listener, for instance.
      • splitByPageNumbers

        public java.util.List<PdfDocument> splitByPageNumbers​(java.util.List<java.lang.Integer> pageNumbers)
        Splits the document by page numbers.
        Parameters:
        pageNumbers - the numbers of pages from which another document is to be started. If the first element is not 1, then 1 is implied (i.e. the first split document will start from page 1 in any case).
        Returns:
        the list of resultant documents. By warned that they are not closed.
      • splitByPageCount

        public void splitByPageCount​(int pageCount,
                                     PdfSplitter.IDocumentReadyListener documentReady)
        Splits a document into smaller documents with no more than @pageCount pages each.
        Parameters:
        pageCount - the biggest possible number of pages in a split document.
        documentReady - the event listener which is called when another document is ready. You can close this document in this listener, for instance.
      • splitByPageCount

        public java.util.List<PdfDocument> splitByPageCount​(int pageCount)
        Splits a document into smaller documents with no more than @pageCount pages each.
        Parameters:
        pageCount - the biggest possible number of pages in a split document.
        Returns:
        the list of resultant documents. By warned that they are not closed.
      • extractPageRanges

        public java.util.List<PdfDocument> extractPageRanges​(java.util.List<PageRange> pageRanges)
        Extracts the specified page ranges from a document.
        Parameters:
        pageRanges - the list of page ranges for each of the resultant document.
        Returns:
        the list of the resultant documents for each of the specified page range. Be warned that these documents are not closed.
      • extractPageRange

        public PdfDocument extractPageRange​(PageRange pageRange)
        Extracts the specified page ranges from a document.
        Parameters:
        pageRange - the page range to be extracted from the document.
        Returns:
        the resultant document containing the pages specified by the provided page range. Be warned that this document is not closed.
      • getPdfDocument

        public PdfDocument getPdfDocument()
        Gets the document to be split.
        Returns:
        PdfDocument to be split.
      • getNextPdfWriter

        protected PdfWriter getNextPdfWriter​(PageRange documentPageRange)
        This method is called when another split document is to be created. You can override this method and return your own PdfWriter depending on your needs.
        Parameters:
        documentPageRange - the page range of the original document to be included in the document being created now.
        Returns:
        the PdfWriter instance for the document which is being created.
      • splitByOutlines

        public java.util.List<PdfDocument> splitByOutlines​(java.util.List<java.lang.String> outlineTitles)
        Split a document by outline title (bookmark name), find outline by name and places the entire hierarchy in a separate document ( outlines and pages ) .
        Parameters:
        outlineTitles - list of outline titles .
        Returns:
        Collection of PdfDocument which contains split parts of a document
      • splitByOutline

        private PdfDocument splitByOutline​(java.lang.String outlineTitle)
      • getNextRange

        private PageRange getNextRange​(int startPage,
                                       int endPage,
                                       long size)
      • getAbsoluteTreeNextOutline

        private PdfOutline getAbsoluteTreeNextOutline​(PdfOutline outline)
        the next element in the entire hierarchy
        Parameters:
        outline - *
      • getPageByOutline

        private PdfPage getPageByOutline​(int fromPage,
                                         PdfOutline outline)
      • xrefLength

        private long xrefLength​(int size)