PDFium Delphi Component Docs

Structure traversal and cache

Component: TPdf  ·  Unit: PDFium
Read tagged PDF structure incrementally or reuse complete revision-aware page snapshots

ReadStructureElements

function ReadStructureElements(PageNumber: Integer; const Options: TPdfStructureReadOptions; out Status: TPdfStructureReadStatus): TPdfStructureElements;

Uses iterative pre-order traversal and returns a caller-owned flattened snapshot with stable Level and ParentIndex values

Each TPdfStructureElement also reports hierarchy facts through MarkedContentIDs, ChildCount, ChildMarkedContentIDs, and AttributeCount, table structure through HasHeaders, HeadersIds, and ColSpan, and the print and reference sentinels HasPrintField and HasReference

Role mapping is exposed through RoleMappedNamespaceUri and RoleMappedTypeName, associated files through HasAssociatedFile, AssociatedFileRelationship, AssociatedFileDescription, AssociatedFileDeclaredInCatalog, AssociatedFileDeclaredInStructure, AssociatedFileInEmbeddedFilesNameTree, AssociatedFileHasReadingOrder, and AssociatedFileReadingOrderIndex, and annotation facts through AnnotationSubtype, AnnotationContents, AnnotationAlternateText, IsArtifact, the widget sentinels WidgetCount and HasAppearance, and FieldAlternateName

MaxDepth, MaxElements, MaxAttributeValues, and DeadlineMilliseconds bound native work and managed allocation

IncludeAttributes=False keeps structure text, hierarchy, and MCIDs while skipping attribute value materialisation

Status.Completed is false when any budget is reached, the deadline expires, or a visitor stops traversal

Status.ElementsVisited and Status.AttributeValuesVisited count the work performed, while Status.DepthLimitReached, Status.ElementLimitReached, Status.AttributeLimitReached, and Status.DeadlineReached identify which budget stopped the walk

VisitStructureElements

function VisitStructureElements(PageNumber: Integer; const Options: TPdfStructureReadOptions; Visitor: TPdfStructureElementVisitor; out Status: TPdfStructureReadStatus): Integer;

Calls Visitor once for each element without allocating the complete page array

Set the callback's KeepGoing parameter to false for a normal early stop reported by Status.VisitorStopped

Each callback receives managed element data that can be retained after the callback returns and no native structure handle is exposed

StructureElementsForPage

property StructureElementsForPage[PageNumber: Integer]: TPdfStructureElements; // read only

Reads any one-based page without changing PageNumber or firing OnPageChange

Complete default-budget results enter the shared LRU cache used by StructureElements, TPdfView.StructureElements, readable content, reflow, structured text, and accessibility validation

Nested dynamic arrays and attribute blobs are deep copied so changing a returned snapshot cannot modify the cache or the PDF

StructureCacheCapacity

property StructureCacheCapacity: Integer; // read and write, default 8

Limits the number of complete page snapshots retained by least-recently-used order

Set the capacity to zero to release cached snapshots and disable future caching

Negative capacity values raise EPdfError

StructureCacheCount

property StructureCacheCount: Integer; // read only

Returns the current number of valid page snapshots

StructureCacheHitCount and StructureCacheMissCount

property StructureCacheHitCount: Int64; // read only
property StructureCacheMissCount: Int64; // read only

Expose cumulative lookup telemetry for the component instance

Edits invalidate the affected page or the complete cache while preserving cumulative counters

Default budgets

MaxDepth256
MaxElements100000
MaxAttributeValues100000
DeadlineMilliseconds0 for no deadline
IncludeAttributesTrue

See Also

StructureElements, ReadableContent, ValidatePdfUaStructureElements