diff --git a/src/display/api.js b/src/display/api.js index 43954cabd..20d8226fc 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -229,7 +229,7 @@ const DefaultStandardFontDataFactory = * already populated with data, or a parameter object. * @returns {PDFDocumentLoadingTask} */ -function getDocument(src) { +function getDocument(src = {}) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof src === "string" || src instanceof URL) { src = { url: src }; @@ -237,14 +237,6 @@ function getDocument(src) { src = { data: src }; } } - if (typeof src !== "object") { - throw new Error("Invalid parameter in getDocument, need parameter object."); - } - if (!src.url && !src.data && !src.range) { - throw new Error( - "Invalid parameter object: need either .data, .range or .url" - ); - } const task = new PDFDocumentLoadingTask(); const { docId } = task; @@ -423,6 +415,9 @@ function getDocument(src) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { throw new Error("Not implemented: createPDFNetworkStream"); } + if (!url) { + throw new Error("getDocument - no `url` parameter provided."); + } const createPDFNetworkStream = params => { if ( typeof PDFJSDev !== "undefined" &&