Package com.itextpdf.kernel.utils
Class PdfSplitter
- java.lang.Object
-
- com.itextpdf.kernel.utils.PdfSplitter
-
public class PdfSplitter extends java.lang.ObjectHelper class to split the document based on some condition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePdfSplitter.IDocumentReadyListenerThe event listener which is called when another document is ready.private static classPdfSplitter.SplitReadyListener
-
Field Summary
Fields Modifier and Type Field Description private IMetaInfometaInfoprivate PdfDocumentpdfDocumentprivate booleanpreserveOutlinesprivate booleanpreserveTagged
-
Constructor Summary
Constructors Constructor Description PdfSplitter(PdfDocument pdfDocument)Creates a new instance of PdfSplitter class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private PdfDocumentcreatePdfDocument(PageRange currentPageRange)PdfDocumentextractPageRange(PageRange pageRange)Extracts the specified page ranges from a document.java.util.List<PdfDocument>extractPageRanges(java.util.List<PageRange> pageRanges)Extracts the specified page ranges from a document.private PdfOutlinegetAbsoluteTreeNextOutline(PdfOutline outline)the next element in the entire hierarchyprotected PdfWritergetNextPdfWriter(PageRange documentPageRange)This method is called when another split document is to be created.private PageRangegetNextRange(int startPage, int endPage, long size)private PdfPagegetPageByOutline(int fromPage, PdfOutline outline)PdfDocumentgetPdfDocument()Gets the document to be split.voidsetEventCountingMetaInfo(IMetaInfo metaInfo)Sets theIMetaInfothat will be used duringPdfDocumentcreation.voidsetPreserveOutlines(boolean preserveOutlines)If original document has outlines, then by default all resultant document will also have outlines.voidsetPreserveTagged(boolean preserveTagged)If original document is tagged, then by default all resultant document will also be tagged.private PdfDocumentsplitByOutline(java.lang.String outlineTitle)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 ) .java.util.List<PdfDocument>splitByPageCount(int pageCount)Splits a document into smaller documents with no more than @pageCount pages each.voidsplitByPageCount(int pageCount, PdfSplitter.IDocumentReadyListener documentReady)Splits a document into smaller documents with no more than @pageCount pages each.java.util.List<PdfDocument>splitByPageNumbers(java.util.List<java.lang.Integer> pageNumbers)Splits the document by page numbers.voidsplitByPageNumbers(java.util.List<java.lang.Integer> pageNumbers, PdfSplitter.IDocumentReadyListener documentReady)Splits the document by page numbers.java.util.List<PdfDocument>splitBySize(long size)Splits the document basing on the given size specified in bytes.private longxrefLength(int size)
-
-
-
Field Detail
-
pdfDocument
private PdfDocument pdfDocument
-
preserveTagged
private boolean preserveTagged
-
preserveOutlines
private boolean preserveOutlines
-
metaInfo
private IMetaInfo metaInfo
-
-
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 theIMetaInfothat will be used duringPdfDocumentcreation.- 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:
PdfDocumentto 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 ownPdfWriterdepending 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
PdfDocumentwhich contains split parts of a document
-
createPdfDocument
private PdfDocument createPdfDocument(PageRange currentPageRange)
-
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)
-
-