Skip to content

Improve error handling when parsing page-structTrees #19824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/core/struct_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down