Class OutlineHandler
java.lang.Object
com.itextpdf.html2pdf.attach.impl.OutlineHandler
A
OutlineHandler
handles creating outlines for marks. Marks are extracted via interface IOutlineMarkExtractor
.
This class is not reusable and a new instance shall be created for every new conversion process.
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.itextpdf.kernel.pdf.PdfOutline
The current outline.protected Deque
String, com.itextpdf.kernel.pdf.PdfDictionary>> The destinations in process.The levels in process.protected IOutlineMarkExtractor
The mark extractor defines what part of element will be used to create outline -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected OutlineHandler
addOutlineAndDestToDocument
(ITagWorker tagWorker, com.itextpdf.styledxmlparser.node.IElementNode element, ProcessorContext context) Adds the outline and the destination.static OutlineHandler
createHandler
(IOutlineMarkExtractor extractor) Creates an OutlineHandler with customIOutlineMarkExtractor
static OutlineHandler
Creates an OutlineHandler with standardTagOutlineMarkExtractor
and predefined mappings.protected String
generateOutlineName
(com.itextpdf.styledxmlparser.node.IElementNode element) Generate the outline name.protected String
generateUniqueDestinationName
(com.itextpdf.styledxmlparser.node.IElementNode element) Generate the unique destination name.Gets the destination name prefix.Get mark extractor.getMarkPriorityMapping
(String markName) Gets the mark from priority mapping.boolean
hasMarkPriorityMapping
(String markName) Checks for tag in priority mapping.putAllMarksPriorityMappings
(Map<String, Integer> mappings) Put all marks into priority mappings.putMarkPriorityMapping
(String markName, Integer priority) Put mark into priority mapping.void
reset()
Resets the current state so that thisOutlineHandler
is ready to process new documentvoid
setDestinationNamePrefix
(String destinationNamePrefix) Sets the destination name prefix.protected OutlineHandler
setDestinationToElement
(ITagWorker tagWorker, com.itextpdf.styledxmlparser.node.IElementNode element) Sets the destination to element.setMarkExtractor
(IOutlineMarkExtractor extractor) Set mark extractor.
-
Field Details
-
currentOutline
protected com.itextpdf.kernel.pdf.PdfOutline currentOutlineThe current outline. -
destinationsInProcess
The destinations in process. -
levelsInProcess
The levels in process. -
markExtractor
The mark extractor defines what part of element will be used to create outline
-
-
Constructor Details
-
OutlineHandler
public OutlineHandler()Creates an OutlineHandler with standardTagOutlineMarkExtractor
.
-
-
Method Details
-
createStandardHandler
Creates an OutlineHandler with standardTagOutlineMarkExtractor
and predefined mappings.- Returns:
- the outline handler
-
createHandler
Creates an OutlineHandler with customIOutlineMarkExtractor
- Parameters:
-
extractor
- the mark extractor - Returns:
- the outline handler
-
getMarkExtractor
Get mark extractor.- Returns:
- the mark extractor
-
setMarkExtractor
Set mark extractor.- Parameters:
-
extractor
- the mark extractor - Returns:
- the outline handler
-
putMarkPriorityMapping
Put mark into priority mapping.- Parameters:
-
markName
- the mark name -
priority
- the priority - Returns:
- the outline handler
-
putAllMarksPriorityMappings
Put all marks into priority mappings.- Parameters:
-
mappings
- the mappings - Returns:
- the outline handler
-
getMarkPriorityMapping
Gets the mark from priority mapping.- Parameters:
-
markName
- the mark name - Returns:
- the tag priority mapping
-
hasMarkPriorityMapping
Checks for tag in priority mapping.- Parameters:
-
markName
- the mark name - Returns:
- true, if the tag name is listed in the tag priorities mapping
-
reset
public void reset()Resets the current state so that thisOutlineHandler
is ready to process new document -
setDestinationNamePrefix
Sets the destination name prefix. The destination name prefix serves as the prefix for the destination names created in thegenerateUniqueDestinationName(com.itextpdf.styledxmlparser.node.IElementNode)
method.- Parameters:
-
destinationNamePrefix
- the destination name prefix
-
getDestinationNamePrefix
Gets the destination name prefix. The destination name prefix serves as the prefix for the destination names created in thegenerateUniqueDestinationName(com.itextpdf.styledxmlparser.node.IElementNode)
method.- Returns:
- the destination name prefix
-
generateUniqueDestinationName
protected String generateUniqueDestinationName(com.itextpdf.styledxmlparser.node.IElementNode element) Generate the unique destination name. The destination name is a unique identifier for the outline so it is generated for the outline in theaddOutlineAndDestToDocument(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.styledxmlparser.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
method. You can override this method to set your own way to generate the destination names, to avoid the destination name conflicts when merging several PDF files created by html2pdf.- Parameters:
-
element
- the element - Returns:
- the unique destination name
-
generateOutlineName
Generate the outline name. This method is used in theaddOutlineAndDestToDocument(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.styledxmlparser.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
method. You can override this method to set your own way to generate the outline names.- Parameters:
-
element
- the element - Returns:
- the unique destination name
-
addOutlineAndDestToDocument
protected OutlineHandler addOutlineAndDestToDocument(ITagWorker tagWorker, com.itextpdf.styledxmlparser.node.IElementNode element, ProcessorContext context) Adds the outline and the destination. Adds the outline and its corresponding the destination to the PDF document if the priority mapping is set for the element.- Parameters:
-
tagWorker
- the tag worker -
element
- the element -
context
- the processor context - Returns:
- the outline handler
-
setDestinationToElement
protected OutlineHandler setDestinationToElement(ITagWorker tagWorker, com.itextpdf.styledxmlparser.node.IElementNode element) Sets the destination to element. Sets the destination previously created in theaddOutlineAndDestToDocument(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.styledxmlparser.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
method to the tag worker element.- Parameters:
-
tagWorker
- the tag worker -
element
- the element - Returns:
- the outline handler
-