diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index 083230c2bc423..cdd12dfa85d7f 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -42,6 +42,7 @@ class StructTreeRoot { this.roleMap = new Map(); this.structParentIds = null; this.kidRefToPosition = undefined; + this.parentTree = null; } getKidPosition(kidRef) { @@ -70,6 +71,11 @@ class StructTreeRoot { init() { this.readRoleMap(); + const parentTree = this.dict.get("ParentTree"); + if (!parentTree) { + return; + } + this.parentTree = new NumberTree(parentTree, this.xref); } #addIdToPage(pageRef, id, type) { @@ -771,7 +777,7 @@ class StructTreePage { return; } - const parentTree = this.rootDict.get("ParentTree"); + const { parentTree } = this.root; if (!parentTree) { return; } @@ -782,10 +788,9 @@ class StructTreePage { } const map = new Map(); - const numberTree = new NumberTree(parentTree, this.xref); if (Number.isInteger(id)) { - const parentArray = numberTree.get(id); + const parentArray = parentTree.get(id); if (Array.isArray(parentArray)) { for (const ref of parentArray) { if (ref instanceof Ref) { @@ -799,7 +804,7 @@ class StructTreePage { return; } for (const [elemId, type] of ids) { - const obj = numberTree.get(elemId); + const obj = parentTree.get(elemId); if (obj) { const elem = this.addNode(this.xref.fetchIfRef(obj), map); if (