diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index fa27a14c0..2b8bcc181 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -565,7 +565,10 @@ class StructElementNode { const kids = this.dict.get("K"); if (Array.isArray(kids)) { for (const kid of kids) { - const element = this.parseKid(pageObjId, kid); + const element = this.parseKid( + pageObjId, + this.dict.xref.fetchIfRef(kid) + ); if (element) { this.kids.push(element); } @@ -592,33 +595,26 @@ class StructElementNode { }); } - // Find the dictionary for the kid. - let kidDict = null; - if (kid instanceof Ref) { - kidDict = this.dict.xref.fetch(kid); - } else if (kid instanceof Dict) { - kidDict = kid; - } - if (!kidDict) { + if (!(kid instanceof Dict)) { return null; } - const pageRef = kidDict.getRaw("Pg"); + + const pageRef = kid.getRaw("Pg"); if (pageRef instanceof Ref) { pageObjId = pageRef.toString(); } - const type = - kidDict.get("Type") instanceof Name ? kidDict.get("Type").name : null; + const type = kid.get("Type") instanceof Name ? kid.get("Type").name : null; if (type === "MCR") { if (this.tree.pageDict.objId !== pageObjId) { return null; } - const kidRef = kidDict.getRaw("Stm"); + const kidRef = kid.getRaw("Stm"); return new StructElement({ type: StructElementType.STREAM_CONTENT, refObjId: kidRef instanceof Ref ? kidRef.toString() : null, pageObjId, - mcid: kidDict.get("MCID"), + mcid: kid.get("MCID"), }); } @@ -626,7 +622,7 @@ class StructElementNode { if (this.tree.pageDict.objId !== pageObjId) { return null; } - const kidRef = kidDict.getRaw("Obj"); + const kidRef = kid.getRaw("Obj"); return new StructElement({ type: StructElementType.OBJECT, refObjId: kidRef instanceof Ref ? kidRef.toString() : null, @@ -636,7 +632,7 @@ class StructElementNode { return new StructElement({ type: StructElementType.ELEMENT, - dict: kidDict, + dict: kid, }); } }