|
iText 9.8.0 API
|
The class is a helper which is used to correctly create structure tree for layout element (with keeping right order for tags). More...
Public Member Functions |
|
| LayoutTaggingHelper (PdfDocument document, bool immediateFlush) | |
| Instantiates a new LayoutTaggingHelper instance for managing layout-level tagging. More... |
|
| virtual void | AddKidsHint< _T0 > (TagTreePointer parentPointer, IEnumerable< _T0 > newKids) |
| Registers child hints for a pre-existing PDF tag (mapped via TagTreePointer). More... |
|
| virtual void | AddKidsHint< _T0 > (IPropertyContainer parent, IEnumerable< _T0 > newKids) |
| Registers children hints for a parent element or renderer (append mode). More... |
|
| virtual void | AddKidsHint< _T0 > (IPropertyContainer parent, IEnumerable< _T0 > newKids, int insertIndex) |
| Registers children hints for a parent element or renderer (with insert position). More... |
|
| virtual void | AddKidsHint (TaggingHintKey parentKey, ICollection< TaggingHintKey > newKidsKeys) |
| Registers children hints using TaggingHintKey s directly (append mode). More... |
|
| virtual void | AddKidsHint (TaggingHintKey parentKey, ICollection< TaggingHintKey > newKidsKeys, int insertIndex) |
| Registers children hints using TaggingHintKey s directly (with insert position). More... |
|
| virtual void | SetRoleHint (IPropertyContainer hintOwner, String role) |
| Overrides the PDF role for an element's tag in the structure tree. More... |
|
| virtual bool | IsArtifact (IPropertyContainer hintOwner) |
| Checks whether the given container is marked as an artifact (non-accessible). More... |
|
| virtual void | MarkArtifactHint (IPropertyContainer hintOwner) |
| Marks an element or renderer as an artifact (non-accessible content). More... |
|
| virtual void | MarkArtifactHint (TaggingHintKey hintKey) |
| Marks a hint key as an artifact (non-accessible content). More... |
|
| virtual TagTreePointer | UseAutoTaggingPointerAndRememberItsPosition (IRenderer renderer) |
| Saves the current auto-tagging pointer position and returns it for temporary use. More... |
|
| virtual void | RestoreAutoTaggingPointerPosition (IRenderer renderer) |
| Restores the auto-tagging pointer to a previously saved position. More... |
|
| virtual IList< TaggingHintKey > | GetKidsHint (TaggingHintKey parent) |
| Gets the unmodifiable list of direct children for a parent hint. More... |
|
| virtual IList< TaggingHintKey > | GetAccessibleKidsHint (TaggingHintKey parent) |
| Gets the list of accessible children for a parent hint, flattening non-accessible intermediate nodes. More... |
|
| virtual TaggingHintKey | GetParentHint (IPropertyContainer hintOwner) |
| Gets the parent hint of a given element or renderer. More... |
|
| virtual TaggingHintKey | GetParentHint (TaggingHintKey hintKey) |
| Gets the direct parent hint of a hint key. More... |
|
| virtual TaggingHintKey | GetAccessibleParentHint (TaggingHintKey hintKey) |
| Gets the nearest accessible parent hint, skipping non-accessible intermediate nodes. More... |
|
| virtual void | ReleaseFinishedHints () |
| Incrementally finalizes and releases finished hints from the tagging structure. More... |
|
| virtual void | ReleaseAllHints () |
| Forces finalization and release of all hints, clearing the entire tagging structure. More... |
|
| virtual bool | CreateTag (IRenderer renderer, TagTreePointer tagPointer) |
| Creates or retrieves a PDF tag for a renderer, ensuring it exists in the structure tree. More... |
|
| virtual bool | CreateTag (TaggingHintKey hintKey, TagTreePointer tagPointer) |
| Creates a PDF tag for a hint key, ensuring it exists in the structure tree. More... |
|
| virtual void | FinishTaggingHint (IPropertyContainer hintOwner) |
| Marks an element or renderer as logically complete and applies tagging rules. More... |
|
| virtual int | ReplaceKidHint (TaggingHintKey kidHintKey, ICollection< TaggingHintKey > newKidsHintKeys) |
| Replaces one child hint with multiple new child hints. More... |
|
| virtual int | MoveKidHint (TaggingHintKey hintKeyOfKidToMove, TaggingHintKey newParent) |
| Moves a child hint from its current parent to a new parent (appended). More... |
|
| virtual int | MoveKidHint (TaggingHintKey hintKeyOfKidToMove, TaggingHintKey newParent, int insertIndex) |
| Moves a child hint from its current parent to a new parent at a specific position. More... |
|
| virtual String | CreateStructureElementId (String prefix) |
| Created a unique id for a structureElement. More... |
|
| virtual PdfDocument | GetPdfDocument () |
| Gets the PDF document associated with this helper. More... |
|
Static Public Member Functions |
|
| static void | AddTreeHints (iText.Layout.Tagging.LayoutTaggingHelper taggingHelper, IRenderer rootRenderer) |
| Recursively registers tagging hints from a renderer tree, preserving the logical structure. More... |
|
| static TaggingHintKey | GetHintKey (IPropertyContainer container) |
| Retrieves an existing tagging hint key for the given container without creating one. More... |
|
| static TaggingHintKey | GetOrCreateHintKey (IPropertyContainer container) |
| Gets or creates a tagging hint key for the given container. More... |
|
The class is a helper which is used to correctly create structure tree for layout element (with keeping right order for tags).
|
inline |
Instantiates a new LayoutTaggingHelper instance for managing layout-level tagging.
Instantiates a new LayoutTaggingHelper instance for managing layout-level tagging.
This helper maintains a tree of tagging hints that represent the logical structure of a PDF document and coordinates tag creation in the PDF structure tree. It automatically registers default tagging rules for standard roles (e.g., TABLE, THEAD, TFOOT, TH) based on the PDF version.
| document | the PDF document being created or modified |
| immediateFlush | if true , parent tags will be flushed as soon as all their children are flushed; if false , tag flushing is deferred until explicitly requested |
|
inlinevirtual |
Registers children hints using TaggingHintKey s directly (append mode).
Registers children hints using TaggingHintKey s directly (append mode).
This variant works directly with TaggingHintKey objects instead of containers, useful when you already have the hint keys or when working with internal hint manipulation.
| parentKey | the parent hint key |
| newKidsKeys | the hint keys of children to add |
|
inlinevirtual |
Registers children hints using TaggingHintKey s directly (with insert position).
Registers children hints using TaggingHintKey s directly (with insert position).
This variant works directly with TaggingHintKey objects and supports specifying an insertion position. This is the core method that other addKidsHint overloads delegate to.
| parentKey | the parent hint key |
| newKidsKeys | the hint keys of children to add |
| insertIndex | the position at which to insert the first child; negative means append at end |
|
inlinevirtual |
Registers children hints for a parent element or renderer (append mode).
Registers children hints for a parent element or renderer (append mode).
This method declares that the given children should appear as kids of the parent in the PDF structure tree. Children are appended to any existing children. This method creates TaggingHintKey s for each child if they don't already exist.
| parent | the parent element or renderer |
| newKids | the children to add under the parent (can be elements or renderers) |
| _T0 | : | IPropertyContainer |
|
inlinevirtual |
Registers children hints for a parent element or renderer (with insert position).
Registers children hints for a parent element or renderer (with insert position).
This method declares that the given children should appear as kids of the parent in the PDF structure tree, optionally at a specific position. If insertIndex is negative, children are appended.
If the parent tag has already been created in the PDF structure tree, this method will relocate child tags into the parent.
| parent | the parent element or renderer |
| newKids | the children to add under the parent |
| insertIndex | the position at which to insert the first child; negative means append at end |
| _T0 | : | IPropertyContainer |
|
inlinevirtual |
Registers child hints for a pre-existing PDF tag (mapped via TagTreePointer).
Registers child hints for a pre-existing PDF tag (mapped via TagTreePointer).
This method is used when you have a pre-existing tag structure element (from a PDF that already contains tags) and need to associate new children with it. The helper creates a TaggingDummyElement wrapper to manage the pre-existing tag and adds the new children under it.
This is useful for merging external PDFs or handling documents that were partially tagged before layout processing.
| parentPointer | the iText.Kernel.Pdf.Tagutils.TagTreePointer pointing to the pre-existing parent tag |
| newKids | the children to add under the parent tag |
| _T0 | : | IPropertyContainer |
|
inlinestatic |
Recursively registers tagging hints from a renderer tree, preserving the logical structure.
Recursively registers tagging hints from a renderer tree, preserving the logical structure.
This utility method traverses the renderer hierarchy and calls AddKidsHint(iText.Layout.IPropertyContainer, System.Collections.Generic.IEnumerable
| taggingHelper | the helper instance managing tags |
| rootRenderer | the root renderer of the tree to process recursively |
|
inlinevirtual |
Created a unique id for a structureElement.
| prefix | a prefix to prepend to the id |
|
inlinevirtual |
Creates or retrieves a PDF tag for a renderer, ensuring it exists in the structure tree.
Creates or retrieves a PDF tag for a renderer, ensuring it exists in the structure tree.
This method is typically called by a renderer before it writes marked content to ensure the tag is positioned correctly in the PDF structure tree. If the tag already exists, it is not recreated.
For artifacts, returns false without creating a tag. For non-accessible hints, the pointer is positioned at the nearest accessible parent. For accessible hints, a tag is created with the correct sibling index.
| renderer | the renderer whose tag should be created |
| tagPointer | the tag tree pointer to use for positioning; the pointer may be moved during tag creation |
true if a tag was created, false if one already existed or hint is artifact/non-accessible
|
inlinevirtual |
Creates a PDF tag for a hint key, ensuring it exists in the structure tree.
Creates a PDF tag for a hint key, ensuring it exists in the structure tree.
This is the core tag creation method. It:
false if the hint is an artifact tagPointer.addTag(...) The pointer may be modified during this method to position it at the correct parent and index. That's why if auto-tagging pointer is to be used, make sure to rely on UseAutoTaggingPointerAndRememberItsPosition(iText.Layout.Renderer.IRenderer) and RestoreAutoTaggingPointerPosition(iText.Layout.Renderer.IRenderer) functionality.
| hintKey | the hint key to create a tag for |
| tagPointer | the tag tree pointer to use for positioning |
true if a tag was created, false if artifact or already exists
|
inlinevirtual |
Marks an element or renderer as logically complete and applies tagging rules.
Marks an element or renderer as logically complete and applies tagging rules.
Call this method when an element has finished its layout or rendering and will not receive new children. This triggers:
true , the hint is marked as finished false , the hint remains unfinished (rules can block finishing) Important: A hint cannot receive new children or be relocated after finishing. Always try to finish hints in parent-to-child order (or at least ensure children are finished before parents) if possible.
For non-accessible hints, rules are bypassed and the hint is marked finished immediately. For artifacts, this method has no effect.
| hintOwner | the element or renderer to finish |
|
inlinevirtual |
Gets the list of accessible children for a parent hint, flattening non-accessible intermediate nodes.
Gets the list of accessible children for a parent hint, flattening non-accessible intermediate nodes.
This method returns only accessible children (those with a non-null role). Non-accessible intermediate nodes (grouping nodes) are recursively flattened, and their accessible descendants are included in the returned list.
For example, if a parent has a non-accessible child that contains two accessible children, this method returns those two accessible children directly.
Returns an empty list if the parent has no accessible children.
| parent | the parent hint key |
|
inlinevirtual |
Gets the nearest accessible parent hint, skipping non-accessible intermediate nodes.
Gets the nearest accessible parent hint, skipping non-accessible intermediate nodes.
This method traverses up the hint tree, skipping non-accessible hints (grouping nodes), and returns the first accessible parent found. Useful when you need to know the logical parent regardless of grouping structure.
| hintKey | the child hint key |
null if no accessible parent exists
|
inlinestatic |
Retrieves an existing tagging hint key for the given container without creating one.
Retrieves an existing tagging hint key for the given container without creating one.
If no hint key has been created for this container, returns null. Use GetOrCreateHintKey(iText.Layout.IPropertyContainer) if you need to ensure a hint exists.
| container | the element or renderer to retrieve the hint for |
null if not yet created
|
inlinevirtual |
Gets the unmodifiable list of direct children for a parent hint.
Gets the unmodifiable list of direct children for a parent hint.
This method returns all direct children hints, including non-accessible intermediate nodes. For accessible children only, use GetAccessibleKidsHint(TaggingHintKey).
Returns an empty list if the parent has no children.
| parent | the parent hint key |
|
inlinestatic |
Gets or creates a tagging hint key for the given container.
Gets or creates a tagging hint key for the given container.
If a hint key already exists for this container, returns it. Otherwise, creates a new TaggingHintKey , stores it in the container's properties, and returns it.
For iText.Layout.Element.ILargeElement s that are not yet complete, the hint key is stored on the element itself rather than on the renderer, to preserve the hint across renderer recreation.
If the container's role is iText.Kernel.Pdf.Tagging.StandardRoles.ARTIFACT , the created hint is automatically marked as artifact and finished.
| container | the element or renderer to get or create a hint for |
|
inlinevirtual |
Gets the parent hint of a given element or renderer.
Gets the parent hint of a given element or renderer.
This method retrieves the direct parent hint for the given container by first obtaining its hint key and then looking up the parent.
| hintOwner | the element or renderer whose parent should be retrieved |
null if this is a root or has no hint
|
inlinevirtual |
Gets the direct parent hint of a hint key.
| hintKey | the child hint key |
null if this is a root
|
inlinevirtual |
Gets the PDF document associated with this helper.
|
inlinevirtual |
Checks whether the given container is marked as an artifact (non-accessible).
Checks whether the given container is marked as an artifact (non-accessible).
An artifact is content that should not appear in the accessibility tree, such as decorative elements. Artifacts are not included in the PDF structure tree.
This method checks:
true true false | hintOwner | the element or renderer to check |
true if the container is an artifact, false otherwise
|
inlinevirtual |
Marks an element or renderer as an artifact (non-accessible content).
Marks an element or renderer as an artifact (non-accessible content).
Artifacts are excluded from the PDF accessibility tree and are not exposed to assistive technologies. Use this for decorative elements, borders, backgrounds, or other non-semantic content.
This method:
| hintOwner | the element or renderer to mark as artifact |
|
inlinevirtual |
Marks a hint key as an artifact (non-accessible content).
Marks a hint key as an artifact (non-accessible content).
This is the core implementation of artifact marking. It:
| hintKey | the hint key to mark as artifact |
|
inlinevirtual |
Moves a child hint from its current parent to a new parent (appended).
Moves a child hint from its current parent to a new parent (appended).
This method removes a child from its current parent and re-parents it to the new parent, appending it to the new parent's children list.
For a specific insertion position in the new parent, use MoveKidHint(TaggingHintKey, TaggingHintKey, int).
| hintKeyOfKidToMove | the child hint to move |
| newParent | the new parent hint |
-1 if move failed
|
inlinevirtual |
Moves a child hint from its current parent to a new parent at a specific position.
Moves a child hint from its current parent to a new parent at a specific position.
This method is similar to MoveKidHint(TaggingHintKey, TaggingHintKey) but allows specifying the insertion index in the new parent's children list. Negative index means append.
Errors are logged if:
| hintKeyOfKidToMove | the child hint to move |
| newParent | the new parent hint |
| insertIndex | the position at which to insert the child; negative means append |
-1 if move failed
|
inlinevirtual |
Forces finalization and release of all hints, clearing the entire tagging structure.
Forces finalization and release of all hints, clearing the entire tagging structure.
This is a comprehensive cleanup operation that:
Call this at the end of document layout or when discarding the layout state entirely. This method should leave all internal structures empty after completion.
|
inlinevirtual |
Incrementally finalizes and releases finished hints from the tagging structure.
Incrementally finalizes and releases finished hints from the tagging structure.
This method scans all hints and releases those that:
When a hint is released:
immediateFlush is enabled, parent tags are flushed if all kids are flushed This is an incremental operation useful for memory management. Call this periodically (e.g., at end of each page or logical boundary) to progressively finalize tags.
|
inlinevirtual |
Replaces one child hint with multiple new child hints.
Replaces one child hint with multiple new child hints.
This method is useful when a single renderer needs to expand into multiple child tags. It removes the old child from its parent and inserts the new children at the same position.
Errors are logged and the operation fails if:
The method returns the index where the replacement occurred, which can be used for further hint tree manipulation if needed.
| kidHintKey | the child hint to be replaced |
| newKidsHintKeys | the new child hints to insert at the replacement position |
-1 if replacement failed
|
inlinevirtual |
Restores the auto-tagging pointer to a previously saved position.
Restores the auto-tagging pointer to a previously saved position.
This method retrieves the pointer position saved by UseAutoTaggingPointerAndRememberItsPosition(iText.Layout.Renderer.IRenderer) and moves the auto-tagging pointer back to that location. If no saved position exists for the renderer, does nothing.
Important: Always call this in a finally block or error handling path to ensure the pointer is restored even if an exception occurs during custom tagging operations.
| renderer | the renderer whose position should be restored |
|
inlinevirtual |
Overrides the PDF role for an element's tag in the structure tree.
Overrides the PDF role for an element's tag in the structure tree.
By default, a tag's role is determined from the element's accessibility properties. This method allows you to override that role at runtime. The override is applied when the tag is created.
Important: Apply role overrides before calling FinishTaggingHint(iText.Layout.IPropertyContainer). Once tagging rules have been applied during finishing, re-applying the same rules for a new role will not occur.
| hintOwner | the element or renderer whose tag role should be overridden |
| role | the new PDF role (e.g., iText.Kernel.Pdf.Tagging.StandardRoles.SPAN , iText.Kernel.Pdf.Tagging.StandardRoles.STRONG ) |
|
inlinevirtual |
Saves the current auto-tagging pointer position and returns it for temporary use.
Saves the current auto-tagging pointer position and returns it for temporary use.
This method is useful when a renderer needs to temporarily modify the auto-tagging pointer for custom tag creation or structure manipulation. The saved position can be restored later using RestoreAutoTaggingPointerPosition(iText.Layout.Renderer.IRenderer).
Usage pattern (with try-finally):
TagTreePointer ptr = helper.useAutoTaggingPointerAndRememberItsPosition(renderer);
try
ptr.addTag("CustomRole");
// ... custom operations ...
finally
helper.restoreAutoTaggingPointerPosition(renderer);
}
}
| renderer | the renderer whose position should be saved (used as a key for restoration) |