diff --git a/src/core/obj.js b/src/core/obj.js index 10469f05b044c..e4eb369bf8383 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -479,7 +479,7 @@ class Catalog { }; const obj = this.catDict.get("ViewerPreferences"); - const prefs = Object.create(null); + let prefs = null; if (isDict(obj)) { for (const key in ViewerPreferencesValidators) { @@ -583,6 +583,9 @@ class Catalog { } if (prefValue !== undefined) { + if (!prefs) { + prefs = Object.create(null); + } prefs[key] = prefValue; } else { info(`Bad value in ViewerPreferences for "${key}".`); diff --git a/src/display/api.js b/src/display/api.js index 028bcff4d7671..d3209cd758482 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -663,7 +663,8 @@ class PDFDocumentProxy { /** * @returns {Promise} A promise that is resolved with an {Object} containing - * the viewer preferences. + * the viewer preferences, or `null` when no viewer preferences are present + * in the PDF file. */ getViewerPreferences() { return this._transport.getViewerPreferences(); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 2cda2eecd25af..ddaaf21cd44b8 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -24,7 +24,6 @@ import { createPromiseCapability, FontType, InvalidPDFException, - isEmptyObj, MissingPDFException, OPS, PasswordException, @@ -846,9 +845,7 @@ describe("api", function () { return pdfDoc.getViewerPreferences(); }) .then(function (prefs) { - expect( - typeof prefs === "object" && prefs !== null && isEmptyObj(prefs) - ).toEqual(true); + expect(prefs).toEqual(null); loadingTask.destroy().then(done); })