Merge pull request #19824 from Snuffleupagus/getStructTree-catch-errors

Improve error handling when parsing page-structTrees
This commit is contained in:
Jonas Jenwald 2025-04-17 15:21:55 +02:00 committed by GitHub
commit f1e20cd668
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -707,10 +707,18 @@ class Page {
// Ensure that the structTree will contain the page's annotations. // Ensure that the structTree will contain the page's annotations.
await this._parsedAnnotations; await this._parsedAnnotations;
const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [ try {
structTreeRoot, const structTree = await this.pdfManager.ensure(
]); this,
return this.pdfManager.ensure(structTree, "serializable"); "_parseStructTree",
[structTreeRoot]
);
const data = await this.pdfManager.ensure(structTree, "serializable");
return data;
} catch (ex) {
warn(`getStructTree: "${ex}".`);
return null;
}
} }
/** /**

View File

@ -757,7 +757,10 @@ class StructTreePage {
const parent = dict.get("P"); 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)) { if (!this.addTopLevelNode(dict, element)) {
map.delete(dict); map.delete(dict);
} }