Package com.itextpdf.tool.xml.html
Class AbstractTagProcessor
java.lang.Object
com.itextpdf.tool.xml.html.AbstractTagProcessor
- All Implemented Interfaces:
CssAppliersAware
,TagProcessor
- Direct Known Subclasses:
Anchor
,Body
,Break
,Div
,Header
,HorizontalRule
,Image
,Link
,Meta
,NonSanitizedTag
,OrderedUnorderedList
,OrderedUnorderedListItem
,ParaGraph
,Span
,Style
,Table
,TableData
,TableRow
,Title
,XML
Abstract TagProcessor that allows setting the configuration object to a
protected member variable.
Implements
Extend from this class instead of implementing
Implements
TagProcessor.startElement(WorkerContext, Tag)
and
TagProcessor.endElement(WorkerContext, Tag, List)
to calculate font sizes and add
new pages if needed.Extend from this class instead of implementing
TagProcessor
to
benefit from auto fontsize metric conversion to pt and
page-break-before/after insertion. Override
start(WorkerContext, Tag)
and
end(WorkerContext, Tag, List)
in your extension.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CssAppliers
private final FontSizeTranslator
For some tags, if they have their own not inherited DIR attribute, this attribute will definitely not be applied for itext layout. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontent
(WorkerContext ctx, Tag tag, String content) This method is called if there is text content encountered between the opening and closing tags this TagProcessor is mapped to.protected Paragraph
currentContentToParagraph
(List<Element> currentContent, boolean addNewLines) Default apply CSS to false and tag to null.currentContentToParagraph
(List<Element> currentContent, boolean addNewLines, boolean applyCSS, Tag tag, WorkerContext ctx) Adds currentContent list to a paragraph element.protected void
end
(WorkerContext ctx, Tag tag, List<Element> currentContent) Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List)
.endElement
(WorkerContext ctx, Tag tag, List<Element> currentContent) Checks forCSS.Property.PAGE_BREAK_AFTER
, if the value is always aChunk.NEXTPAGE
is added to the currentContentList after callingend(WorkerContext, Tag, List)
.getCSSResolver
(WorkerContext context) Utility method that fetches the CSSResolver from the if any and if it uses the default key.getHtmlPipelineContext
(WorkerContext context) Utility method that fetches the HtmlPipelineContext used if any and if it uses the default key.private String
protected int
getRunDirection
(Tag tag) protected void
protected void
boolean
Defaults to false.void
setCssAppliers
(CssAppliers cssAppliers) start
(WorkerContext ctx, Tag tag) Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.startElement(WorkerContext, Tag)
.startElement
(WorkerContext ctx, Tag tag) Calculates any found font size to pt values and set it in the CSS before callingstart(WorkerContext, Tag)
.
Checks forCSS.Property.PAGE_BREAK_BEFORE
, if the value is always aChunk.NEXTPAGE
added before the implementorsstart(WorkerContext, Tag)
method.textContent
(WorkerContext ctx, Tag tag, String content) protected void
updateParagraphFontIfNeeded
(Phrase p, Element child) In case child font is of bigger size than paragraph font, text overlapping may occur.
-
Field Details
-
fontsizeTrans
-
cssAppliers
-
ignoreDirAttribute
For some tags, if they have their own not inherited DIR attribute, this attribute will definitely not be applied for itext layout. For the most common such tags we use this set to ignore DIR attribute, in order to avoid unnecessary adjustments in XmlWorker. However if parent of these tags have DIR attribute, it may be applied to these tags. -
tree
-
-
Constructor Details
-
AbstractTagProcessor
public AbstractTagProcessor()
-
-
Method Details
-
getCSSResolver
Utility method that fetches the CSSResolver from the if any and if it uses the default key.- Parameters:
context
- the WorkerContext- Returns:
- CSSResolver
- Throws:
NoCustomContextException
- if the context of theCssResolverPipeline
could not be found.
-
getHtmlPipelineContext
public HtmlPipelineContext getHtmlPipelineContext(WorkerContext context) throws NoCustomContextException Utility method that fetches the HtmlPipelineContext used if any and if it uses the default key.- Parameters:
context
- the WorkerContext- Returns:
- a HtmlPipelineContext
- Throws:
NoCustomContextException
- if the context of theHtmlPipelineContext
could not be found.
-
startElement
Calculates any found font size to pt values and set it in the CSS before callingstart(WorkerContext, Tag)
.
Checks forCSS.Property.PAGE_BREAK_BEFORE
, if the value is always aChunk.NEXTPAGE
added before the implementorsstart(WorkerContext, Tag)
method.- Specified by:
startElement
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encountered- Returns:
- Element an Element to add to the current content;
-
start
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.startElement(WorkerContext, Tag)
. ThestartElement(WorkerContext, Tag)
calls this method after or before doing certain stuff, (see it's description).- Parameters:
ctx
- the WorkerContexttag
- the tag- Returns:
- an element to be added to current content, may be null
-
content
Description copied from interface:TagProcessor
This method is called if there is text content encountered between the opening and closing tags this TagProcessor is mapped to.- Specified by:
content
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encounteredcontent
- the text content between the tags this TagProcessor is mapped to.- Returns:
- the element to add to the currentContent list
-
getParentDirection
-
getRunDirection
-
textContent
-
endElement
Checks forCSS.Property.PAGE_BREAK_AFTER
, if the value is always aChunk.NEXTPAGE
is added to the currentContentList after callingend(WorkerContext, Tag, List)
.- Specified by:
endElement
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encounteredcurrentContent
- a list of content possibly created by TagProcessing of inner tags, and bystartElement
andcontent
methods of thisTagProcessor
.- Returns:
- the resulting element to add to the document or a content stack.
-
end
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List)
. TheendElement(WorkerContext, Tag, List)
calls this method after or before doing certain stuff, (see it's description).- Parameters:
ctx
- the WorkerContexttag
- the tagcurrentContent
- the content created from e.g. inner tags, inner content and not yet added to document.- Returns:
- a List containing iText Element objects
-
isStackOwner
public boolean isStackOwner()Defaults to false.- Specified by:
isStackOwner
in interfaceTagProcessor
- Returns:
- true if the tag implementation must keep it's own currentContent stack.
- See Also:
-
currentContentToParagraph
public List<Element> currentContentToParagraph(List<Element> currentContent, boolean addNewLines, boolean applyCSS, Tag tag, WorkerContext ctx) Adds currentContent list to a paragraph element. If addNewLines is true a Paragraph object is returned, else a NoNewLineParagraph object is returned.- Parameters:
currentContent
- Listof the current elements to be added. addNewLines
- boolean to declare which paragraph element should be returned, true if new line should be added or not.applyCSS
- true if CSS should be applied on the paragraph.tag
- the relevant tag.ctx
- the WorkerContext.- Returns:
- a List of paragraphs.
-
currentContentToParagraph
public final List<Element> currentContentToParagraph(List<Element> currentContent, boolean addNewLines) Default apply CSS to false and tag to null.- Parameters:
currentContent
- Listof the current elements to be added. addNewLines
- boolean to declare which paragraph element should be returned, true if new line should be added or not.- Returns:
- a List with paragraphs
- See Also:
-
setCssAppliers
- Specified by:
setCssAppliers
in interfaceCssAppliersAware
- Parameters:
cssAppliers
- the CssAppliers
-
getCssAppliers
- Specified by:
getCssAppliers
in interfaceCssAppliersAware
- Returns:
- the CssAppliers
-
createParagraph
-
doRtlIndentCorrections
-
invertTextAlignForParagraph
-
invertTextAlignForParagraph
-
updateParagraphFontIfNeeded
In case child font is of bigger size than paragraph font, text overlapping may occur. This happens because leading of the lines in paragraph is set based on paragraph font.
-