diff --git a/src/core/document.js b/src/core/document.js index b1e1caaec..7324c9980 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -707,10 +707,18 @@ class Page { // Ensure that the structTree will contain the page's annotations. await this._parsedAnnotations; - const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [ - structTreeRoot, - ]); - return this.pdfManager.ensure(structTree, "serializable"); + try { + const structTree = await this.pdfManager.ensure( + this, + "_parseStructTree", + [structTreeRoot] + ); + const data = await this.pdfManager.ensure(structTree, "serializable"); + return data; + } catch (ex) { + warn(`getStructTree: "${ex}".`); + return null; + } } /** diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index a8766e92e..59ba40cb6 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -757,7 +757,10 @@ class StructTreePage { const parent = dict.get("P"); - if (!parent || isName(parent.get("Type"), "StructTreeRoot")) { + if ( + !(parent instanceof Dict) || + isName(parent.get("Type"), "StructTreeRoot") + ) { if (!this.addTopLevelNode(dict, element)) { map.delete(dict); }