Skip to content

Commit f1e20cd

Browse files
Merge pull request #19824 from Snuffleupagus/getStructTree-catch-errors
Improve error handling when parsing page-structTrees
2 parents 2f7d163 + bf553f2 commit f1e20cd

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/core/document.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,18 @@ class Page {
707707
// Ensure that the structTree will contain the page's annotations.
708708
await this._parsedAnnotations;
709709

710-
const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [
711-
structTreeRoot,
712-
]);
713-
return this.pdfManager.ensure(structTree, "serializable");
710+
try {
711+
const structTree = await this.pdfManager.ensure(
712+
this,
713+
"_parseStructTree",
714+
[structTreeRoot]
715+
);
716+
const data = await this.pdfManager.ensure(structTree, "serializable");
717+
return data;
718+
} catch (ex) {
719+
warn(`getStructTree: "${ex}".`);
720+
return null;
721+
}
714722
}
715723

716724
/**

src/core/struct_tree.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,10 @@ class StructTreePage {
757757

758758
const parent = dict.get("P");
759759

760-
if (!parent || isName(parent.get("Type"), "StructTreeRoot")) {
760+
if (
761+
!(parent instanceof Dict) ||
762+
isName(parent.get("Type"), "StructTreeRoot")
763+
) {
761764
if (!this.addTopLevelNode(dict, element)) {
762765
map.delete(dict);
763766
}

0 commit comments

Comments
 (0)