diff --git a/src/components/PDFData.vue b/src/components/PDFData.vue index 044cba3..71a4c15 100644 --- a/src/components/PDFData.vue +++ b/src/components/PDFData.vue @@ -8,10 +8,20 @@ const log = debug('app:components/PDFData'); import range from 'lodash/range'; -function getDocument(url) { - // Using import statement in this way allows Webpack - // to treat pdf.js as an async dependency so we can - // avoid adding it to one of the main bundles +function getDocument(url, httpHeaders) { + + // Using import statement in this way allows Webpack + // to treat pdf.js as an async dependency so we can + // avoid adding it to one of the main bundles + + if (httpHeaders) { + return import( + /* webpackChunkName: 'pdfjs-dist' */ + 'pdfjs-dist/webpack').then(pdfjs => pdfjs.getDocument({ + url: url, + httpHeaders: httpHeaders, + })); + } return import( /* webpackChunkName: 'pdfjs-dist' */ 'pdfjs-dist/webpack').then(pdfjs => pdfjs.getDocument(url)); @@ -40,6 +50,10 @@ export default { type: String, required: true, }, + httpHeaders: { + type: Object, + required: false, + }, }, data() { @@ -51,7 +65,7 @@ export default { watch: { url: { handler(url) { - getDocument(url) + getDocument(url, this.httpHeaders) .then(pdf => (this.pdf = pdf)) .catch(response => { this.$emit('document-errored', {text: 'Failed to retrieve PDF', response}); diff --git a/src/components/PDFDocument.vue b/src/components/PDFDocument.vue index 0e83e28..c9b5fb5 100644 --- a/src/components/PDFDocument.vue +++ b/src/components/PDFDocument.vue @@ -9,7 +9,7 @@ @pages-reset="fitWidth" > [] + }, }, computed: { diff --git a/src/components/PDFPage.vue b/src/components/PDFPage.vue index ce1c15f..53f6a3e 100644 --- a/src/components/PDFPage.vue +++ b/src/components/PDFPage.vue @@ -1,5 +1,8 @@