public class TagTreePointer extends Object
TagTreePointer class is used to modify the document's tag tree. At any given moment, instance of this class
'points' at the specific position in the tree (at the specific tag), however every instance can be freely moved around
the tree primarily using moveToKid(int) and moveToParent() methods. For the current tag you can add new tags,
modify it's role and properties, etc. Also, using instance of this class, you can change tag position in the tag structure,
you can flush current tag or remove it.
There could be any number of the instances of this class, simultaneously pointing to different (or the same) parts of
the tag structure. Because of this, you can for example remove the tag at which another instance is currently pointing.
In this case, this another instance becomes invalid, and invocation of any method on it will result in exception. To make
given instance valid again, use moveToRoot() method.
| Constructor and Description |
|---|
TagTreePointer(PdfDocument document)
Creates
TagTreePointer instance. |
TagTreePointer(TagTreePointer tagPointer)
A copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
TagTreePointer |
addAnnotationTag(PdfAnnotation annotation)
Adds a new content item for the given
PdfAnnotation under the current tag. |
TagTreePointer |
addTag(AccessibilityProperties properties)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(int index,
AccessibilityProperties properties)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(int index,
String role)
Adds a new tag with given role to the tag structure.
|
TagTreePointer |
addTag(String role)
Adds a new tag with given role to the tag structure.
|
TagTreePointer |
flushParentsIfAllKidsFlushed()
For current tag and all of it's parents consequentially checks if the following constraints apply,
and flushes the tag if they do or stops if they don't:
tag is not already flushed;
tag is not in waiting state (see
WaitingTagsManager);
tag is not the root tag;
tag has no kids or all of the kids are either flushed themselves or
(if they are a marked content reference) belong to the flushed page. |
TagTreePointer |
flushTag()
Flushes current tag and all it's descendants.
|
TagStructureContext |
getContext() |
PdfStream |
getCurrentContentStream() |
PdfPage |
getCurrentPage() |
PdfDocument |
getDocument() |
int |
getIndexInParentKidsList()
Defines index of the current tag in the parent's kids list.
|
List<String> |
getKidsRoles()
Gets current tag kids roles.
|
PdfNamespace |
getNamespaceForNewTags()
Gets a
PdfNamespace which will be set to every new tag created by this TagTreePointer instance. |
AccessibilityProperties |
getProperties()
Gets accessibility properties of the current tag.
|
String |
getRole()
Gets current tag role.
|
TagReference |
getTagReference()
Creates a reference to the current tag, which could be used to associate a content on the PdfCanvas with current tag.
|
TagReference |
getTagReference(int index)
Creates a reference to the current tag, which could be used to associate a content on the PdfCanvas with current tag.
|
boolean |
isPointingToSameTag(TagTreePointer otherPointer)
Checks if this
TagTreePointer is pointing at the same tag as the giving TagTreePointer. |
TagTreePointer |
moveToKid(int kidIndex)
Moves this
TagTreePointer instance to the kid of the current tag. |
TagTreePointer |
moveToKid(int n,
String role)
Moves this
TagTreePointer instance to the nth descendant of the current tag which has the given role. |
TagTreePointer |
moveToKid(String role)
Moves this
TagTreePointer instance to the first descendant of the current tag which has the given role. |
TagTreePointer |
moveToParent()
Moves this
TagTreePointer instance to the parent of the current tag. |
TagTreePointer |
moveToPointer(TagTreePointer tagTreePointer)
Moves this
TagTreePointer instance to the tag at which given TagTreePointer instance is pointing. |
TagTreePointer |
moveToRoot()
Moves this
TagTreePointer instance to the document root tag. |
TagTreePointer |
relocate(TagTreePointer pointerToNewParent)
Moves current tag to the tag at which given
TagTreePointer points. |
TagTreePointer |
relocateKid(int kidIndex,
TagTreePointer pointerToNewParent)
Moves kid of the current tag to the tag at which given
TagTreePointer points. |
TagTreePointer |
removeTag()
Removes the current tag.
|
TagTreePointer |
setContentStreamForTagging(PdfStream contentStream)
Sometimes, tags are desired to be connected with the content that resides not in the page's content stream,
but rather in the some appearance stream or in the form xObject stream.
|
TagTreePointer |
setNamespaceForNewTags(PdfNamespace namespace)
Sets a
PdfNamespace which will be set to every new tag created by this TagTreePointer instance
if this tag doesn't explicitly define namespace by the means of DefaultAccessibilityProperties.setNamespace(PdfNamespace). |
TagTreePointer |
setNextNewKidIndex(int nextNewKidIndex)
Sets index of the next added to the current tag kid, which could be another tag or content item.
|
TagTreePointer |
setPageForTagging(PdfPage page)
Sets a page which content will be tagged with this instance of
TagTreePointer. |
TagTreePointer |
setRole(String role)
Sets new role to the current tag.
|
public TagTreePointer(PdfDocument document)
TagTreePointer instance. After creation TagTreePointer points at the root tag.
The PdfNamespace for the new tags, which don't explicitly define namespace by the means of
DefaultAccessibilityProperties.setNamespace(PdfNamespace), is set to the value returned by
TagStructureContext.getDocumentDefaultNamespace() on TagTreePointer creation.
See also setNamespaceForNewTags(PdfNamespace).
document - the document, at which tag structure this instance will point.public TagTreePointer(TagTreePointer tagPointer)
tagPointer - the TagTreePointer from which current position and page are copied.public TagTreePointer setPageForTagging(PdfPage page)
TagTreePointer.
To tag page content:
getTagReference() to obtain the reference to the current tag;
TagReference to the PdfCanvas.openTag(TagReference) method of the page's PdfCanvas to start marked content item;
PdfCanvas;
PdfCanvas.closeTag() to finish marked content item.
page - the page which content will be tagged with this instance of TagTreePointer.TagTreePointer instance.public PdfPage getCurrentPage()
TagTreePointer.public TagTreePointer setContentStreamForTagging(PdfStream contentStream)
null for this value, when tagging of this stream content is finished.contentStream - the content stream which content will be tagged with this instance of TagTreePointer
or null if content stream tagging is finishedTagTreePointer instancepublic PdfStream getCurrentContentStream()
TagTreePointer.public TagStructureContext getContext()
TagStructureContext associated with the document to which this pointer belongs.public PdfDocument getDocument()
public TagTreePointer setNamespaceForNewTags(PdfNamespace namespace)
PdfNamespace which will be set to every new tag created by this TagTreePointer instance
if this tag doesn't explicitly define namespace by the means of DefaultAccessibilityProperties.setNamespace(PdfNamespace).
This value has meaning only for the PDF documents of version 2.0 and higher.
It's highly recommended to acquire PdfNamespace class instances via TagStructureContext.fetchNamespace(String).
namespace - a PdfNamespace to be set for the new tags created. If set to null - new tags will have
a namespace set only if it is defined in the corresponding AccessibilityProperties.TagTreePointer instance.TagStructureContext.fetchNamespace(String)public PdfNamespace getNamespaceForNewTags()
PdfNamespace which will be set to every new tag created by this TagTreePointer instance.PdfNamespace which is to be set for the new tags created, or null if one is not defined.setNamespaceForNewTags(PdfNamespace)public TagTreePointer addTag(String role)
TagTreePointer to the added kid.role - role of the new tag.TagTreePointer instance.public TagTreePointer addTag(int index, String role)
TagTreePointer to the added kid.
setNextNewKidIndex(int) and addTag(String).index - zero-based index in kids array of parent tag at which new tag will be added.role - role of the new tag.TagTreePointer instance.public TagTreePointer addTag(AccessibilityProperties properties)
TagTreePointer to the added kid.
AccessibilityProperties.properties - accessibility properties which define a new tag role and other properties.TagTreePointer instance.public TagTreePointer addTag(int index, AccessibilityProperties properties)
TagTreePointer to the added kid.
AccessibilityProperties.
This call is equivalent of calling sequentially setNextNewKidIndex(int) and addTag(AccessibilityProperties).index - zero-based index in kids array of parent tag at which new tag will be added.properties - accessibility properties which define a new tag role and other properties.TagTreePointer instance.public TagTreePointer addAnnotationTag(PdfAnnotation annotation)
PdfAnnotation under the current tag.
TagStructureContext.getAutoTaggingPointer()). If you want to add annotation tag manually, be sure to use
PdfPage.addAnnotation(int, PdfAnnotation, boolean) method with false for boolean flag.annotation - PdfAnnotation to be tagged.TagTreePointer instance.public TagTreePointer setNextNewKidIndex(int nextNewKidIndex)
addTag(String) method,
with relocateKid(int, TagTreePointer) and addAnnotationTag(PdfAnnotation).
TagTreePointer and not to the tag itself, which means
that if you would move the pointer, this property would be applied to the new current tag.nextNewKidIndex - index of the next added kid.TagTreePointer instance.public TagTreePointer removeTag()
TagTreePointer to the current tag parent.
TagStructureContext instance.public TagTreePointer relocateKid(int kidIndex, TagTreePointer pointerToNewParent)
TagTreePointer points.
This method doesn't change neither this instance nor pointerToNewParent position.kidIndex - zero-based index of the current tag's kid to be relocated.pointerToNewParent - the TagTreePointer which is positioned at the tag which will become kid's new parent.TagTreePointer instance.public TagTreePointer relocate(TagTreePointer pointerToNewParent)
TagTreePointer points.
This method doesn't change either this instance or pointerToNewParent position.pointerToNewParent - the TagTreePointer which is positioned at the tag
which will become current tag new parent.TagTreePointer instance.public TagReference getTagReference()
PdfCanvas.openTag(TagReference) and setPageForTagging(PdfPage).public TagReference getTagReference(int index)
PdfCanvas.openTag(TagReference) and setPageForTagging(PdfPage).index - zero-based index in kids array of tag. These indexes define the logical order of the content on the page.public TagTreePointer moveToRoot()
TagTreePointer instance to the document root tag.TagTreePointer instance.public TagTreePointer moveToParent()
TagTreePointer instance to the parent of the current tag.TagTreePointer instance.public TagTreePointer moveToKid(int kidIndex)
TagTreePointer instance to the kid of the current tag.kidIndex - zero-based index of the current tag kid to which pointer will be moved.TagTreePointer instance.public TagTreePointer moveToKid(String role)
TagTreePointer instance to the first descendant of the current tag which has the given role.
If there are no direct kids of the tag with such role, further descendants are checked in BFS order.role - role of the current tag descendant to which pointer will be moved.
If there are several descendants with this role, pointer will be moved
to the first kid with such role in BFS order.TagTreePointer instance.public TagTreePointer moveToKid(int n, String role)
TagTreePointer instance to the nth descendant of the current tag which has the given role.
If there are no direct kids of the tag with such role, further descendants are checked in BFS order.n - if there are several descendants with the given role, pointer will be moved to the descendant
which has zero-based index n if you count only the descendants with the given role in BFS order.role - role of the current tag descendant to which pointer will be moved.TagTreePointer instance.public List<String> getKidsRoles()
null.
If kid is a content item, at it's position there will be "MCR" string literal (stands for Marked Content Reference).public TagTreePointer flushTag()
TagTreePointer to the current tag parent.
If some of the descendant tags of the current tag have waiting state (see WaitingTagsManager),
then these tags are considered as not yet finished ones, and they won't be flushed immediately,
but they will be flushed, when waiting state is removed.
TagTreePointer instance.public TagTreePointer flushParentsIfAllKidsFlushed()
WaitingTagsManager);
TagStructureContext.flushPageTags(PdfPage)
for the tags which have just lost their waiting state and might be not flushed only because they had one.
This helps to eliminate hanging (not flushed) tags when they don't have waiting state anymore.TagTreePointer instance.public AccessibilityProperties getProperties()
public String getRole()
public TagTreePointer setRole(String role)
role - new role to be set.TagTreePointer instance.public int getIndexInParentKidsList()
public TagTreePointer moveToPointer(TagTreePointer tagTreePointer)
TagTreePointer instance to the tag at which given TagTreePointer instance is pointing.tagTreePointer - a TagTreePointer that points at the tag which will become the current tag
of this instance.TagTreePointer instance.public boolean isPointingToSameTag(TagTreePointer otherPointer)
TagTreePointer is pointing at the same tag as the giving TagTreePointer.otherPointer - a TagTreePointer which is checked against this instance on whether they point
at the same tag.TagTreePointer instances point at the same tag, false otherwise.Copyright © 1998–2023 iText Group NV. All rights reserved.