PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
struct_tree.h
1// Copyright (c) 2026 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_STRUCT_TREE_H_INCLUDED_
4#define PDFSDK_CXX_STRUCT_TREE_H_INCLUDED_
5
6#include <string>
7#include <string_view>
8
10
11#include "forward_declarations.h"
12#include "object.h"
13
14namespace PDF {
15
31public:
33 StructTreeElement() noexcept = default;
34
41
47
53 bool Equals(const StructTreeElement& rhs) const noexcept;
54
55#ifndef SWIG
56 explicit operator bool() const noexcept { return static_cast<bool>(m_obj); }
57 bool operator==(const StructTreeElement& rhs) const noexcept { return Equals(rhs); }
58#endif
59
65 void SetType(PDAtom type);
66
71 PDAtom GetType() const;
72
77 std::string GetID() const;
78
88 void SetID(std::string_view id);
89
94 void SetTitle(std::wstring_view title);
95
100 std::wstring GetTitle() const;
101
106 void SetAltText(std::wstring_view altText);
107
112 std::wstring GetAltText() const;
113
118 void SetActualText(std::wstring_view actualText);
119
124 std::wstring GetActualText() const;
125
131 void SetLanguage(std::wstring_view lang);
132
137 std::wstring GetLanguage() const;
138
144 size_t GetNumAttrObjs() const;
145
151 Object GetAttrObj(size_t index) const;
152
158 int GetAttrObjRevision(size_t index) const;
159
166 void InsertAttrObj(size_t index, const Object& attrObj);
167
172 void RemoveAttrObj(const Object& attrObj);
173
178 size_t GetNumClasses() const;
179
185 PDAtom GetClass(size_t index) const;
186
192 int GetClassRevision(size_t index) const;
193
200 void AddClass(PDAtom name);
201
206 void RemoveClass(PDAtom name);
207
212 int GetRevision() const;
213
219
227
236 bool IsDetached() const;
237
242 size_t GetNumKids() const;
243
250 PDStructTreeKidType GetKidType(size_t index) const;
251
273 void RemoveKid(size_t index);
274
280 StructTreeElement GetKidElement(size_t index) const;
281
289 void InsertKidElement(size_t index, const StructTreeElement& kid);
290
296 Page GetKidMCPage(size_t index) const;
297
303 int GetKidMCID(size_t index) const;
304
310 Object GetKidMCStm(size_t index) const;
311
317 Object GetKidMCStmOwn(size_t index) const;
318
333 void InsertKidMC(size_t index,
334 const Page& page,
335 const Element& mc,
336 const Object& stm = Object(),
337 const Object& stmOwn = Object());
338
350 void InsertKidMCID(size_t index,
351 const Page& page,
352 int mcid,
353 const Object& stm = Object(),
354 const Object& stmOwn = Object());
355
361 Page GetKidOBJRPage(size_t index) const;
362
368 Object GetKidOBJRObject(size_t index) const;
369
378 void InsertKidOBJR(size_t index, const Page& page, const Object& object);
379
380private:
381 friend class StructTreeRoot;
382
383 explicit StructTreeElement(const Object& object) noexcept;
384
385 Object m_obj;
386};
387
401public:
403 StructTreeRoot() noexcept = default;
404
411
417
423 bool Equals(const StructTreeRoot& rhs) const noexcept;
424
425#ifndef SWIG
426 explicit operator bool() const noexcept { return static_cast<bool>(m_obj); }
427 bool operator==(const StructTreeRoot& rhs) const noexcept { return Equals(rhs); }
428#endif
429
435 size_t ClassMapGetNumAttrObjs(PDAtom name) const;
436
443 Object ClassMapGetAttrObj(PDAtom name, size_t index) const;
444
451 void ClassMapInsertAttrObj(PDAtom name, size_t index, const Object& attrObj);
452
458 void ClassMapRemoveAttrObj(PDAtom name, const Object& attrObj);
459
464 void ClassMapRemoveClass(PDAtom name);
465
468
475 void RoleMapPut(PDAtom from, PDAtom to);
476
482 PDAtom RoleMapGet(PDAtom from) const;
483
488 void RoleMapRemove(PDAtom from);
489
498
503 size_t GetNumKids() const;
504
510 StructTreeElement GetKid(size_t index) const;
511
518 void InsertKid(size_t index, const StructTreeElement& element);
519
526 void RemoveKid(size_t index);
527
533 StructTreeElement FindElementByID(std::string_view id) const;
534
542 StructTreeElement GetMCParent(const Page& page, const Element& mc) const;
543
550 StructTreeElement GetMCIDParent(const Page& page, int mcid) const;
551
558
559private:
560 explicit StructTreeRoot(const Object& object) noexcept;
561
562 Object m_obj;
563};
564
565} // namespace PDF
566
567#include "struct_tree_impl.inl"
568
569#endif // PDFSDK_CXX_STRUCT_TREE_H_INCLUDED_
Represents an element of the content array.
Definition element.h:29
Represents a PDF object.
Definition object.h:25
Represents a leaf node (Page Object).
Definition page.h:20
A structure element in a document's logical structure (tag) tree.
Definition struct_tree.h:30
void RemoveAttrObj(const Object &attrObj)
Removes the given attribute object (and its revision) from the element.
void SetID(std::string_view id)
Sets the element identifier (the /ID entry) and updates the document's ID tree so the element can be ...
int GetAttrObjRevision(size_t index) const
Gets the revision number that the attribute object at index applies to.
Object GetKidMCStmOwn(size_t index) const
Gets the object owning the marked content's content stream.
void SetAltText(std::wstring_view altText)
Sets the alternate description used by assistive technology (the /Alt entry).
void AddClass(PDAtom name)
Adds a class name to the element, applying it to the element's current revision number....
void IncrementRevision()
Increments the element's revision number. Attribute objects and classes added afterwards are associat...
Object GetKidMCStm(size_t index) const
Gets the content stream containing the marked-content kid at index.
void SetLanguage(std::wstring_view lang)
Sets the natural language of the element's content (the /Lang entry, e.g. L"en-US").
int GetKidMCID(size_t index) const
Gets the marked-content identifier of the kid at index.
bool IsDetached() const
Checks if the element is detached from a structure tree.
size_t GetNumKids() const
Gets the number of kids (the /K entry).
Object GetPdfObject() const
Gets the PDF object backing this structure element.
int GetClassRevision(size_t index) const
Gets the revision number that the class at index applies to.
StructTreeElement GetKidElement(size_t index) const
Gets the structure element kid at index.
void SetTitle(std::wstring_view title)
Sets the human-readable title (the /T entry).
PDAtom GetClass(size_t index) const
Gets the class name at index.
void InsertAttrObj(size_t index, const Object &attrObj)
Associates an attribute object with the element at index, applying it to the element's current revisi...
Object GetAttrObj(size_t index) const
Gets the attribute object at index.
std::wstring GetLanguage() const
Gets the natural language (the /Lang entry).
void InsertKidOBJR(size_t index, const Page &page, const Object &object)
Associates a whole object (e.g. an annotation) with the element as an object-reference kid at index,...
size_t GetNumAttrObjs() const
Gets the number of attribute objects associated with the element (the /A entry).
std::wstring GetAltText() const
Gets the alternate description (the /Alt entry).
std::wstring GetActualText() const
Gets the replacement text (the /ActualText entry).
std::wstring GetTitle() const
Gets the title (the /T entry).
void SetActualText(std::wstring_view actualText)
Sets the replacement text for the element's content (the /ActualText entry).
Object GetKidOBJRObject(size_t index) const
Gets the object referenced by the object-reference kid at index.
int GetRevision() const
Gets the element's revision number (the /R entry).
PDAtom GetType() const
Gets the structure type (the /S entry).
StructTreeElement GetParent() const
Gets the parent structure element.
void RemoveClass(PDAtom name)
Removes a class name (and its revision) from the element.
void RemoveKid(size_t index)
Removes the kid at index, keeping the document consistent.
void InsertKidMCID(size_t index, const Page &page, int mcid, const Object &stm=Object(), const Object &stmOwn=Object())
Inserts a reference to marked content that already carries mcid as a kid at index.
std::string GetID() const
Gets the element identifier (the /ID entry).
bool Equals(const StructTreeElement &rhs) const noexcept
Compares two elements for identity (same backing object).
StructTreeElement() noexcept=default
Constructs an empty (null) element.
void SetType(PDAtom type)
Sets the structure type - the /S entry (a standard type such as P or H1, or a custom type resolved th...
size_t GetNumClasses() const
Gets the number of class names associated with the element (the /C entry).
Page GetKidMCPage(size_t index) const
Gets the page containing the marked-content kid at index.
void InsertKidElement(size_t index, const StructTreeElement &kid)
Inserts an existing structure element as a kid at index and sets its parent to this element....
PDStructTreeKidType GetKidType(size_t index) const
Gets the kind of the kid at index so the matching typed accessor (GetKidElement, GetKidMC*,...
void InsertKidMC(size_t index, const Page &page, const Element &mc, const Object &stm=Object(), const Object &stmOwn=Object())
Tags a previously-untagged marked-content sequence and inserts it as a kid at index.
Page GetKidOBJRPage(size_t index) const
Gets the page associated with the object-reference kid at index.
static StructTreeElement CreateFromPdfObject(const Object &object)
Wraps an existing structure element dictionary.
The root of a document's logical structure (tag) tree.
Definition struct_tree.h:400
PDAtom RoleMapGet(PDAtom from) const
Gets the standard structure type that from maps to.
StructTreeRoot() noexcept=default
Constructs an empty (null) root.
void RemoveKid(size_t index)
Detaches the top-level kid at index: it is unlinked from the root and its parent link is cleared,...
void ClassMapRemoveAll()
Removes the entire class map.
size_t ClassMapGetNumAttrObjs(PDAtom name) const
Gets the number of attribute objects mapped to class name in the class map.
StructTreeElement GetMCIDParent(const Page &page, int mcid) const
Finds the structure element that owns the given marked-content identifier.
Object GetPdfObject() const
Gets the PDF object backing this structure tree root.
StructTreeElement FindElementByID(std::string_view id) const
Finds a structure element by its identifier via the document's ID tree.
StructTreeElement CreateElement(PDAtom type)
Creates a new, detached structure element of the given type, owned by the same document....
void RoleMapPut(PDAtom from, PDAtom to)
Maps a custom role from to a standard structure type to, so elements typed from are treated as to.
void InsertKid(size_t index, const StructTreeElement &element)
Inserts a structure element as a top-level kid at index and sets its parent to the root....
size_t GetNumKids() const
Gets the number of top-level kids.
Object ClassMapGetAttrObj(PDAtom name, size_t index) const
Gets the attribute object at index mapped to class name.
void ClassMapRemoveClass(PDAtom name)
Removes class name (and all its attribute objects) from the class map.
StructTreeElement GetMCParent(const Page &page, const Element &mc) const
Finds the structure element that owns the given marked content, via the parent tree.
static StructTreeRoot CreateFromPdfObject(const Object &object)
Wraps an existing structure tree root dictionary.
StructTreeElement GetKid(size_t index) const
Gets the top-level structure element at index.
void ClassMapRemoveAttrObj(PDAtom name, const Object &attrObj)
Removes the given attribute object from class name.
bool Equals(const StructTreeRoot &rhs) const noexcept
Compares two roots for identity (same backing object).
void ClassMapInsertAttrObj(PDAtom name, size_t index, const Object &attrObj)
Maps an attribute object to class name at index in the class map.
StructTreeElement GetObjectParent(const Object &object) const
Finds the structure element that owns the given object (e.g. an annotation).
void RoleMapRemove(PDAtom from)
Removes the role mapping for from.
StructTree API.