diff --git a/src/core/catalog.js b/src/core/catalog.js index 64c214344..2ace6fa40 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -82,10 +82,11 @@ class Catalog { get version() { const version = this._catDict.get("Version"); - if (!isName(version)) { - return shadow(this, "version", null); - } - return shadow(this, "version", version.name); + return shadow( + this, + "version", + version instanceof Name ? version.name : null + ); } /** @@ -94,10 +95,11 @@ class Catalog { */ get needsRendering() { const needsRendering = this._catDict.get("NeedsRendering"); - if (!isBool(needsRendering)) { - return shadow(this, "needsRendering", false); - } - return shadow(this, "needsRendering", needsRendering); + return shadow( + this, + "needsRendering", + typeof needsRendering === "boolean" ? needsRendering : false + ); } get collection() { diff --git a/src/core/document.js b/src/core/document.js index 02161e2c1..21373afc2 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -263,12 +263,13 @@ class Page { } get xfaData() { - if (this.xfaFactory) { - return shadow(this, "xfaData", { - bbox: this.xfaFactory.getBoundingBox(this.pageIndex), - }); - } - return shadow(this, "xfaData", null); + return shadow( + this, + "xfaData", + this.xfaFactory + ? { bbox: this.xfaFactory.getBoundingBox(this.pageIndex) } + : null + ); } save(handler, task, annotationStorage) { @@ -784,11 +785,14 @@ class PDFDocument { } get numPages() { + let num = 0; if (this.xfaFactory) { - return shadow(this, "numPages", this.xfaFactory.numberPages); + num = this.xfaFactory.numberPages; + } else if (this.linearization) { + num = this.linearization.numPages; + } else { + num = this.catalog.numPages; } - const linearization = this.linearization; - const num = linearization ? linearization.numPages : this.catalog.numPages; return shadow(this, "numPages", num); } @@ -883,16 +887,16 @@ class PDFDocument { } get xfaFactory() { + let data; if ( this.pdfManager.enableXfa && this.catalog.needsRendering && this.formInfo.hasXfa && !this.formInfo.hasAcroForm ) { - const data = this.xfaData; - return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null); + data = this.xfaData; } - return shadow(this, "xfaFactory", null); + return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null); } get isPureXfa() {