modern-pdf-lib / PdfStructureElement
Class: PdfStructureElement
Defined in: src/accessibility/structureTree.ts:158
A single node in the structure tree.
Structure elements form a tree that mirrors the logical reading order of the document. Each element has a type (e.g. "P", "H1", "Table"), optional attributes, and may contain child elements or marked-content references (MCIDs) that link to the actual page content.
Constructors
Constructor
new PdfStructureElement(
type,options?):PdfStructureElement
Defined in: src/accessibility/structureTree.ts:181
Parameters
type
The structure type (e.g. "P", "H1", "Figure").
options?
Optional attributes for the element.
Returns
PdfStructureElement
Properties
children
readonlychildren:PdfStructureElement[] =[]
Defined in: src/accessibility/structureTree.ts:163
Child structure elements.
mcid?
optionalmcid:number
Defined in: src/accessibility/structureTree.ts:169
Marked content ID linking this element to page content.
options
readonlyoptions:StructureElementOptions
Defined in: src/accessibility/structureTree.ts:166
Optional attributes (alt text, language, title, etc.).
pageIndex?
optionalpageIndex:number
Defined in: src/accessibility/structureTree.ts:172
Zero-based page index this element's content appears on.
parent?
optionalparent:PdfStructureElement
Defined in: src/accessibility/structureTree.ts:175
The parent element (undefined for the root).
type
readonlytype:StructureType
Defined in: src/accessibility/structureTree.ts:160
The structure type of this element.
Methods
addChild()
addChild(
type,options?):PdfStructureElement
Defined in: src/accessibility/structureTree.ts:193
Add a child element to this node.
Parameters
type
The child's structure type.
options?
Optional attributes for the child.
Returns
PdfStructureElement
The newly created child element.
depth()
depth():
number
Defined in: src/accessibility/structureTree.ts:257
Return the depth of this element in the tree (root = 0).
Returns
number
find()
find(
type):PdfStructureElement|undefined
Defined in: src/accessibility/structureTree.ts:233
Find the first descendant (or self) matching the given type.
Parameters
type
Returns
PdfStructureElement | undefined
findAll()
findAll(
type):PdfStructureElement[]
Defined in: src/accessibility/structureTree.ts:245
Find all descendants (and self) matching the given type.
Parameters
type
Returns
PdfStructureElement[]
removeChild()
removeChild(
element):void
Defined in: src/accessibility/structureTree.ts:209
Remove a direct child element.
Parameters
element
PdfStructureElement
The child to remove.
Returns
void
Throws
If the element is not a direct child.
toDict()
toDict(
registry,parentRef,pageRefs):object
Defined in: src/accessibility/structureTree.ts:275
Serialize this element to a PDF dictionary.
Parameters
registry
Object registry for allocating indirect references.
parentRef
Reference to the parent element (or StructTreeRoot).
pageRefs
readonly PdfRef[]
Array of page references indexed by page number.
Returns
object
An object containing the element's dict and its ref.
dict
dict:
PdfDict
ref
ref:
PdfRef
walk()
walk():
PdfStructureElement[]
Defined in: src/accessibility/structureTree.ts:222
Recursively collect all elements in the subtree (depth-first, including this element).
Returns
PdfStructureElement[]