public class TagTreePointer extends Object implements Serializable
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). 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(IAccessibleElement element)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(IAccessibleElement element, boolean keepConnectedToTag)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(int index, IAccessibleElement element)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(int index, IAccessibleElement element, boolean keepConnectedToTag)
Adds a new tag to the tag structure.
|
TagTreePointer |
addTag(int index, PdfName role)
Adds a new tag with given role to the tag structure.
|
TagTreePointer |
addTag(PdfName role)
Adds a new tag with given role to the tag structure.
|
TagTreePointer |
flushTag()
Flushes the current tag and all it's descenders.
|
IAccessibleElement |
getConnectedElement(boolean createIfNotExist)
Gets connected accessible element for the current tag.
|
PdfStream |
getCurrentContentStream() |
PdfPage |
getCurrentPage() |
PdfDocument |
getDocument() |
List<PdfName> |
getKidsRoles()
Gets current element kids roles.
|
AccessibilityProperties |
getProperties()
Gets accessibility properties of the current tag.
|
PdfName |
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 |
isElementConnectedToTag(IAccessibleElement element)
Checks if given IAccessibleElement is connected to some tag.
|
TagTreePointer |
moveToKid(int kidIndex)
Moves this TagTreePointer instance to the kid of the current tag.
|
TagTreePointer |
moveToKid(int n, PdfName role)
Moves this TagTreePointer instance to the kid of the current tag.
|
TagTreePointer |
moveToKid(PdfName role)
Moves this TagTreePointer instance to the kid of the current tag.
|
TagTreePointer |
moveToParent()
Moves this TagTreePointer instance to the parent of the current tag.
|
TagTreePointer |
moveToRoot()
Moves this TagTreePointer instance to the document root tag.
|
TagTreePointer |
moveToTag(IAccessibleElement element)
Moves this TagTreePointer instance to a tag, which is connected with the given accessible element.
|
TagTreePointer |
relocateKid(int kidIndex, TagTreePointer pointerToNewParent)
Moves kid of the current tag to the tag at which given TagTreePointer points.
|
TagStructureContext |
removeElementConnectionToTag(IAccessibleElement element)
Destroys the connection between the given accessible element and the tag to which this element is connected to.
|
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 |
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(PdfName role)
Sets new role to the current tag.
|
public TagTreePointer(PdfDocument document)
TagTreePointer
instance. After creation TagTreePointer
points at the root tag.
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;PdfTagReference
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 finished.
public PdfStream getCurrentContentStream()
TagTreePointer
.
public PdfDocument getDocument()
public TagTreePointer addTag(PdfName role)
TagTreePointer
to the added kid.
role
- role of the new tag.
TagTreePointer
instance.
public TagTreePointer addTag(int index, PdfName role)
TagTreePointer
to the added kid.
setNextNewKidIndex(int)
and addTag(PdfName)
.
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(IAccessibleElement element)
TagTreePointer
to the added kid.
element
- accessible element which represents a new tag.
TagTreePointer
instance.
public TagTreePointer addTag(IAccessibleElement element, boolean keepConnectedToTag)
TagTreePointer
to the added kid.
moveToTag(com.itextpdf.kernel.pdf.tagutils.IAccessibleElement)
for more explanations about tag connections concept.
TagTreePointer
instance would move to connected kid instead of creating tag twice. But if it is added to some other parent, then connection will be removed.
element
- accessible element which represents a new tag.
keepConnectedToTag
- defines if to retain the connection between accessible element and the tag.
TagTreePointer
instance.
public TagTreePointer addTag(int index, IAccessibleElement element)
TagTreePointer
to the added kid.
setNextNewKidIndex(int)
and addTag(IAccessibleElement)
.
index
- zero-based index in kids array of parent tag at which new tag will be added.
element
- accessible element which represents a new tag.
TagTreePointer
instance.
public TagTreePointer addTag(int index, IAccessibleElement element, boolean keepConnectedToTag)
TagTreePointer
to the added kid.
moveToTag(com.itextpdf.kernel.pdf.tagutils.IAccessibleElement)
for more explanations about tag connections concept.
TagTreePointer
instance would move to connected kid instead of creating tag twice. But if it is added to some other parent, then connection will be removed.
This call is equivalent of calling sequentially setNextNewKidIndex(int)
and addTag(IAccessibleElement, boolean)
.
index
- zero-based index in kids array of parent tag at which new tag will be added.
element
- accessible element which represents a new tag.
keepConnectedToTag
- defines if to retain the connection between accessible element and the tag.
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(PdfName)
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 boolean isElementConnectedToTag(IAccessibleElement element)
IAccessibleElement
is connected to some tag. See moveToTag(com.itextpdf.kernel.pdf.tagutils.IAccessibleElement)
for more explanations about tag connections concept.
element
- element to check if it has a connected tag.
public TagStructureContext removeElementConnectionToTag(IAccessibleElement element)
moveToTag(com.itextpdf.kernel.pdf.tagutils.IAccessibleElement)
for more explanations about tag connections concept.
element
- IAccessibleElement
which connection to the tag (if there is one) will be removed.
TagStructureContext
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 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.
TagStructureContext
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.
TagStructureContext
instance.
public TagTreePointer moveToParent()
TagTreePointer
instance to the parent of the current tag.
TagStructureContext
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.
TagStructureContext
instance.
public TagTreePointer moveToKid(PdfName role)
TagTreePointer
instance to the kid of the current tag.
role
- role of the current tag kid to which pointer will be moved. If there is several kids with this role, pointer will be moved to the first kid with such role.
TagStructureContext
instance.
public TagTreePointer moveToKid(int n, PdfName role)
TagTreePointer
instance to the kid of the current tag.
n
- if there is several kids with the given role, pointer will be moved to the kid which is the n'th if you count kids with such role.
role
- role of the current tag kid to which pointer will be moved.
TagStructureContext
instance.
public TagTreePointer moveToTag(IAccessibleElement element)
TagTreePointer
instance to a tag, which is connected with the given accessible element.
The connection between the tag and the accessible element instance is used as a sign that tag is not yet finished and therefore should not be flushed or removed if page tags are flushed or removed. Also, any TagTreePointer
could be immediately moved to the tag with connection via it's connected element by using this method. If accessible element is connected to the tag, then all changes of the role or properties of the element will affect the connected tag role and properties.
For any existing not connected tag the connection could be created using getConnectedElement(boolean)
with true as parameter.
element
- an element which has a connection with some tag.
TagStructureContext
instance.
public List<PdfName> getKidsRoles()
null
. If kid is content item, at its position there will be "MCR" (Marked Content Reference).
public TagTreePointer flushTag()
TagTreePointer
to the current tag parent.
If some of the tags to be flushed are still connected to the accessible elements, then these tags are considered as not yet finished ones, and they won't be flushed immediately, but they will be flushed, when the connection is removed.
TagStructureContext
instance.
public IAccessibleElement getConnectedElement(boolean createIfNotExist)
moveToTag(com.itextpdf.kernel.pdf.tagutils.IAccessibleElement)
for more explanations about tag connections concept.
createIfNotExist
- if true, creates an IAccessibleElement
and connects it to the tag.
IAccessibleElement
if there is one (or if it is created), otherwise null.
public AccessibilityProperties getProperties()
public PdfName getRole()
public TagTreePointer setRole(PdfName role)
role
- new role to be set.
TagStructureContext
instance.
Copyright © 1998–2016 iText Group NV. All rights reserved.