diff --git a/src/core/editor/pdf_editor.js b/src/core/editor/pdf_editor.js index 2ed888c73..8c68f70bb 100644 --- a/src/core/editor/pdf_editor.js +++ b/src/core/editor/pdf_editor.js @@ -27,7 +27,15 @@ import { getNewAnnotationsMap, numberToString, } from "../core_utils.js"; -import { Dict, isName, Name, Ref, RefSet, RefSetCache } from "../primitives.js"; +import { + Dict, + isDict, + isName, + Name, + Ref, + RefSet, + RefSetCache, +} from "../primitives.js"; import { incrementalUpdate, writeValue } from "../writer.js"; import { isArrayEqual, stringToBytes } from "../../shared/util.js"; import { NameTree, NumberTree } from "../name_number_tree.js"; @@ -280,11 +288,7 @@ class PDFEditor { oldRefMapping.put(oldRef, newRef); if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { - if ( - obj instanceof Dict && - isName(obj.get("Type"), "Page") && - !this.currentDocument.pagesMap.has(oldRef) - ) { + if (isDict(obj, "Page") && !this.currentDocument.pagesMap.has(oldRef)) { throw new Error( "Add a deleted page to the document is not supported." ); diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index af57f0a5d..4ecbcb661 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -19,7 +19,7 @@ import { stringToUTF8String, warn, } from "../shared/util.js"; -import { Dict, isName, Name, Ref, RefSetCache } from "./primitives.js"; +import { Dict, isDict, isName, Name, Ref, RefSetCache } from "./primitives.js"; import { stringToAsciiOrUTF16BE, stringToPDFString } from "./string_utils.js"; import { BaseStream } from "./base_stream.js"; import { lookupNormalRect } from "./core_utils.js"; @@ -594,10 +594,7 @@ class StructElementNode { } for (let af of AFs) { af = this.xref.fetchIfRef(af); - if (!(af instanceof Dict)) { - continue; - } - if (!isName(af.get("Type"), "Filespec")) { + if (!isDict(af, "Filespec")) { continue; } if (!isName(af.get("AFRelationship"), "Supplement")) {