Table of Contents

Class TagStructureContext

Namespace
iText.Kernel.Pdf.Tagutils
Assembly
itext.kernel.dll

TagStructureContext class is used to track necessary information of document's tag structure.

public class TagStructureContext
Inheritance
TagStructureContext
Inherited Members

Remarks

TagStructureContext class is used to track necessary information of document's tag structure. It is also used to make some global modifications of the tag tree like removing or flushing page tags, however these two methods and also others are called automatically and are for the most part for internal usage.
There shall be only one instance of this class per PdfDocument . To obtain instance of this class use GetTagStructureContext().

Constructors

TagStructureContext(PdfDocument)

Do not use this constructor, instead use GetTagStructureContext() method.

public TagStructureContext(PdfDocument document)

Parameters

document PdfDocument

the document which tag structure will be manipulated with this class.

Remarks

Do not use this constructor, instead use GetTagStructureContext() method.
Creates TagStructureContext for document. There shall be only one instance of this class per PdfDocument.

TagStructureContext(PdfDocument, PdfVersion)

Do not use this constructor, instead use GetTagStructureContext() method.

public TagStructureContext(PdfDocument document, PdfVersion tagStructureTargetVersion)

Parameters

document PdfDocument

the document which tag structure will be manipulated with this class.

tagStructureTargetVersion PdfVersion

the version of the pdf standard to which the tag structure shall adhere.

Remarks

Do not use this constructor, instead use GetTagStructureContext() method.

Creates TagStructureContext for document. There shall be only one instance of this class per PdfDocument.

Fields

autoTaggingPointer

protected TagTreePointer autoTaggingPointer

Field Value

TagTreePointer

Methods

CheckIfRoleShallBeMappedToStandardRole(string, PdfNamespace)

Checks if the given role and namespace are specified to be obligatory mapped to the standard structure namespace in order to be a valid role in the Tagged PDF.

public virtual bool CheckIfRoleShallBeMappedToStandardRole(string role, PdfNamespace @namespace)

Parameters

role string

a role in the given namespace which mapping necessity is to be checked.

namespace PdfNamespace

a PdfNamespace which this role belongs to, null value refers to the default standard structure namespace.

Returns

bool

true, if the given role in the given namespace is either mapped to the standard structure role or doesn't have to; otherwise false.

CreatePointerForStructElem(PdfStructElem)

Creates a new TagTreePointer which points at given PdfStructElem.

public virtual TagTreePointer CreatePointerForStructElem(PdfStructElem structElem)

Parameters

structElem PdfStructElem

a PdfStructElem for which TagTreePointer will be created.

Returns

TagTreePointer

a new TagTreePointer.

FetchNamespace(string)

This method defines a recommended way to obtain PdfNamespace class instances.

public virtual PdfNamespace FetchNamespace(string namespaceName)

Parameters

namespaceName string

a string defining the namespace name (conventionally a uniform resource identifier, or URI).

Returns

PdfNamespace

PdfNamespace wrapper over either already existing namespace object or over the new one.

Remarks

This method defines a recommended way to obtain PdfNamespace class instances.

Returns either a wrapper over an already existing namespace dictionary in the document or over a new one if such namespace wasn't encountered before. Calling this method is considered as encountering a namespace, i.e. two sequential calls on this method will return the same namespace instance (which is not true in general case of two method calls, for instance if several namespace instances with the same name are created via PdfNamespace constructors and set to the elements of the tag structure, then the last encountered one will be returned by this method). However encountered namespaces will not be added to the document's structure tree root /Namespaces array unless they were set to the certain element of the tag structure.

FlushPageTags(PdfPage)

Flushes the tags which are considered to belong to the given page.

public virtual TagStructureContext FlushPageTags(PdfPage page)

Parameters

page PdfPage

a page which tags will be flushed

Returns

TagStructureContext

current TagStructureContext instance

Remarks

Flushes the tags which are considered to belong to the given page. The logic that defines if the given tag (structure element) belongs to the page is the following: if all the marked content references (dictionary or number references), that are the descendants of the given structure element, belong to the current page - the tag is considered to belong to the page. If tag has descendants from several pages - it is flushed, if all other pages except the current one are flushed.

If some of the page's tags have waiting state (see WaitingTagsManager these tags are considered as not yet finished ones, and they and their children won't be flushed.

GetAutoTaggingPointer()

All tagging logic performed by iText automatically (along with addition of content, annotations etc) uses TagTreePointer returned by this method to manipulate the tag structure.

public virtual TagTreePointer GetAutoTaggingPointer()

Returns

TagTreePointer

the TagTreePointer which is used for all automatic tagging of the document.

Remarks

All tagging logic performed by iText automatically (along with addition of content, annotations etc) uses TagTreePointer returned by this method to manipulate the tag structure. Typically it points at the root tag. This pointer also could be used to tweak auto tagging process (e.g. move this pointer to the Section tag, which would result in placing all automatically tagged content under Section tag).

GetDocumentDefaultNamespace()

A namespace that is used as a default value for the tagging for any new TagTreePointer created (including the pointer returned by GetAutoTaggingPointer() , which implies that automatically created tag structure will be in this namespace by default).

public virtual PdfNamespace GetDocumentDefaultNamespace()

Returns

PdfNamespace

a PdfNamespace which is used as a default value for the document tagging.

Remarks

A namespace that is used as a default value for the tagging for any new TagTreePointer created (including the pointer returned by GetAutoTaggingPointer() , which implies that automatically created tag structure will be in this namespace by default).

By default, this value is defined based on the PDF document version and the existing tag structure inside a document. For the new empty PDF 2.0 documents this namespace is set to PDF_2_0.

This value has meaning only for the PDF documents of version 2.0 and higher.

GetPointerStructElem(TagTreePointer)

Gets PdfStructElem at which TagTreePointer points.

public virtual PdfStructElem GetPointerStructElem(TagTreePointer pointer)

Parameters

pointer TagTreePointer

a TagTreePointer which points at desired PdfStructElem.

Returns

PdfStructElem

a PdfStructElem at which given TagTreePointer points.

Remarks

Gets PdfStructElem at which TagTreePointer points.

NOTE: Be aware that PdfStructElem is a low level class, use it carefully, especially in conjunction with high level TagTreePointer and TagStructureContext classes.

GetRoleMappingResolver(string)

Gets an instance of the IRoleMappingResolver corresponding to the current tag structure target version.

public virtual IRoleMappingResolver GetRoleMappingResolver(string role)

Parameters

role string

a role in the default standard structure namespace which mapping is to be resolved.

Returns

IRoleMappingResolver

a IRoleMappingResolver instance, with the giving role as current.

Remarks

Gets an instance of the IRoleMappingResolver corresponding to the current tag structure target version. This method implies that role is in the default standard structure namespace.

GetRoleMappingResolver(string, PdfNamespace)

Gets an instance of the IRoleMappingResolver corresponding to the current tag structure target version.

public virtual IRoleMappingResolver GetRoleMappingResolver(string role, PdfNamespace @namespace)

Parameters

role string

a role in the given namespace which mapping is to be resolved.

namespace PdfNamespace

a PdfNamespace which this role belongs to.

Returns

IRoleMappingResolver

a IRoleMappingResolver instance, with the giving role in the given PdfNamespace as current.

GetTagPointerById(byte[])

Retrieve a pointer to a structure element by ID.

public virtual TagTreePointer GetTagPointerById(byte[] id)

Parameters

id byte[]

the ID of the element to retrieve

Returns

TagTreePointer

a TagTreePointer to the element in question, or null if there is none.

GetTagPointerByIdString(string)

Retrieve a pointer to a structure element by ID.

public virtual TagTreePointer GetTagPointerByIdString(string id)

Parameters

id string

the ID of the element to retrieve

Returns

TagTreePointer

a TagTreePointer to the element in question, or null if there is none.

Remarks

Retrieve a pointer to a structure element by ID. * The ID will be encoded as a UTF-8 string and passed to GetTagPointerById(byte[]).

GetTagStructureTargetVersion()

Gets the version of the PDF standard to which the tag structure shall adhere.

public virtual PdfVersion GetTagStructureTargetVersion()

Returns

PdfVersion

the tag structure target version

GetWaitingTagsManager()

Gets WaitingTagsManager for the current document.

public virtual WaitingTagsManager GetWaitingTagsManager()

Returns

WaitingTagsManager

document's WaitingTagsManager class instance.

Remarks

Gets WaitingTagsManager for the current document. It allows to mark tags as waiting, which would indicate that they are incomplete and are not ready to be flushed.

NormalizeDocumentRootTag()

Transforms root tags in a way that complies with the tagged PDF specification.

public virtual void NormalizeDocumentRootTag()

Remarks

Transforms root tags in a way that complies with the tagged PDF specification. Depending on PDF version behaviour may differ.
ISO 32000-1 (PDF 1.7 and lower) 14.8.4.2 Grouping Elements
"In a tagged PDF document, the structure tree shall contain a single top-level element; that is, the structure tree root (identified by the StructTreeRoot entry in the document catalogue) shall have only one child in its K (kids) array. If the PDF file contains a complete document, the structure type Document should be used for this top-level element in the logical structure hierarchy. If the file contains a well-formed document fragment, one of the structure types Part, Art, Sect, or Div may be used instead."
For PDF 2.0 and higher root tag is allowed to have only the Document role.

PrepareToDocumentClosing()

A utility method that prepares the current instance of the TagStructureContext for the closing of document.

public virtual void PrepareToDocumentClosing()

Remarks

A utility method that prepares the current instance of the TagStructureContext for the closing of document. Essentially it flushes all the "hanging" information to the document.

RemoveAnnotationTag(PdfAnnotation)

Removes annotation content item from the tag structure.

public virtual TagTreePointer RemoveAnnotationTag(PdfAnnotation annotation)

Parameters

annotation PdfAnnotation

the PdfAnnotation that will be removed from the tag structure

Returns

TagTreePointer

TagTreePointer instance which points at annotation tag parent if annotation was removed, otherwise returns null

Remarks

Removes annotation content item from the tag structure. If annotation is not added to the document or is not tagged, nothing will happen.

RemoveAnnotationTag(PdfAnnotation, bool)

Removes annotation content item from the tag structure and sets autoTaggingPointer if true is passed.

public virtual TagTreePointer RemoveAnnotationTag(PdfAnnotation annotation, bool setAutoTaggingPointer)

Parameters

annotation PdfAnnotation

the PdfAnnotation that will be removed from the tag structure

setAutoTaggingPointer bool

true if TagTreePointer should be set to autoTaggingPointer

Returns

TagTreePointer

TagTreePointer instance which points at annotation tag parent if annotation was removed, otherwise returns null

Remarks

Removes annotation content item from the tag structure and sets autoTaggingPointer if true is passed. If annotation is not added to the document or is not tagged, nothing will happen.

RemoveContentItem(PdfPage, int)

Removes content item from the tag structure.

public virtual TagTreePointer RemoveContentItem(PdfPage page, int mcid)

Parameters

page PdfPage

page, which contains this content item

mcid int

marked content id of this content item

Returns

TagTreePointer

TagTreePointer which points at the parent of the removed content item, or null if there is no such mcid on given page.

Remarks

Removes content item from the tag structure.
Nothing happens if there is no such mcid on given page.

RemovePageTags(PdfPage)

Removes all tags that belong only to this page.

public virtual TagStructureContext RemovePageTags(PdfPage page)

Parameters

page PdfPage

page that defines which tags are to be removed

Returns

TagStructureContext

current TagStructureContext instance

Remarks

Removes all tags that belong only to this page. The logic which defines if tag belongs to the page is described at FlushPageTags(PdfPage).

ResolveMappingToStandardOrDomainSpecificRole(string, PdfNamespace)

Gets an instance of the IRoleMappingResolver which is already in the "resolved" state: it returns role in the standard or domain-specific namespace for the GetRole() and GetNamespace() methods calls which correspond to the mapping of the given role; or null if the given role is not mapped to the standard or domain-specific one.

public virtual IRoleMappingResolver ResolveMappingToStandardOrDomainSpecificRole(string role, PdfNamespace @namespace)

Parameters

role string

a role in the given namespace which mapping is to be resolved.

namespace PdfNamespace

a PdfNamespace which this role belongs to.

Returns

IRoleMappingResolver

an instance of the IRoleMappingResolver which returns false for the CurrentRoleShallBeMappedToStandard() method call; if mapping cannot be resolved to this state, this method returns null, which means that the given role in the specified namespace is not mapped to the standard role in the standard namespace.

SetDocumentDefaultNamespace(PdfNamespace)

Sets a namespace that will be used as a default value for the tagging for any new TagTreePointer created.

public virtual TagStructureContext SetDocumentDefaultNamespace(PdfNamespace @namespace)

Parameters

namespace PdfNamespace

a PdfNamespace which is to be used as a default value for the document tagging.

Returns

TagStructureContext

current TagStructureContext instance.

Remarks

Sets a namespace that will be used as a default value for the tagging for any new TagTreePointer created. See GetDocumentDefaultNamespace() for more info.

Be careful when changing this property value. It is most recommended doing it right after the PdfDocument was created, before any content was added. Changing this value after any content was added might result in the mingled tag structure from the namespaces point of view. So in order to maintain the document consistent but in the namespace different from default, set this value before any modifications to the document were made and before GetAutoTaggingPointer() method was called for the first time.

This value has meaning only for the PDF documents of version 2.0 and higher.

SetForbidUnknownRoles(bool)

If forbidUnknownRoles is set to true, then if you would try to add new tag which has not a standard role and it's role is not mapped through RoleMap, an exception will be raised.

public virtual TagStructureContext SetForbidUnknownRoles(bool forbidUnknownRoles)

Parameters

forbidUnknownRoles bool

new value of the flag

Returns

TagStructureContext

current TagStructureContext instance.

Remarks

If forbidUnknownRoles is set to true, then if you would try to add new tag which has not a standard role and it's role is not mapped through RoleMap, an exception will be raised. Default value - true.