Package com.itextpdf.kernel.utils
Class PdfSplitter
java.lang.Object
com.itextpdf.kernel.utils.PdfSplitter
Helper class to split the document based on some condition.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The event listener which is called when another document is ready. -
Constructor Summary
ConstructorDescriptionPdfSplitter
(PdfDocument pdfDocument) Creates a new instance of PdfSplitter class. -
Method Summary
Modifier and TypeMethodDescriptionextractPageRange
(PageRange pageRange) Extracts the specified page ranges from a document.extractPageRanges
(List<PageRange> pageRanges) Extracts the specified page ranges from a document.protected PdfWriter
getNextPdfWriter
(PageRange documentPageRange) This method is called when another split document is to be created.Gets the document to be split.void
setEventCountingMetaInfo
(IMetaInfo metaInfo) Sets theIMetaInfo
that will be used duringPdfDocument
creation.void
setPreserveOutlines
(boolean preserveOutlines) If original document has outlines, then by default all resultant document will also have outlines.void
setPreserveTagged
(boolean preserveTagged) If original document is tagged, then by default all resultant document will also be tagged.splitByOutlines
(List<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 ) .splitByPageCount
(int pageCount) Splits a document into smaller documents with no more than @pageCount pages each.void
splitByPageCount
(int pageCount, PdfSplitter.IDocumentReadyListener documentReady) Splits a document into smaller documents with no more than @pageCount pages each.splitByPageNumbers
(List<Integer> pageNumbers) Splits the document by page numbers.void
splitByPageNumbers
(List<Integer> pageNumbers, PdfSplitter.IDocumentReadyListener documentReady) Splits the document by page numbers.splitBySize
(long size) Splits the document basing on the given size specified in bytes.
-
Constructor Details
-
PdfSplitter
Creates a new instance of PdfSplitter class.- Parameters:
-
pdfDocument
- the document to be split.
-
-
Method Details
-
setEventCountingMetaInfo
Sets theIMetaInfo
that will be used duringPdfDocument
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
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(List<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
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
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
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
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
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
Gets the document to be split.- Returns:
-
PdfDocument
to be split.
-
getNextPdfWriter
This method is called when another split document is to be created. You can override this method and return your ownPdfWriter
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
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
-