From 0bdf3fe49396ce65232664f1cf4f5618c899aca5 Mon Sep 17 00:00:00 2001 From: Cyrille Savelief Date: Sun, 1 Mar 2020 13:39:24 +0100 Subject: [PATCH 1/4] Add the ability to set HTTP headers in order to be able to load PDF files from protected APIs. --- src/components/PDFData.vue | 24 +++++++++++++++++++----- src/components/PDFViewer.vue | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) 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/PDFViewer.vue b/src/components/PDFViewer.vue index d4ab149..be80408 100644 --- a/src/components/PDFViewer.vue +++ b/src/components/PDFViewer.vue @@ -24,6 +24,7 @@ Date: Sun, 1 Mar 2020 13:54:14 +0100 Subject: [PATCH 2/4] Add a text layer on top of the canvas. --- src/components/PDFDocument.vue | 6 +- src/components/PDFPage.vue | 90 +++- src/components/PDFViewer.vue | 6 +- src/directives/findAndReplaceDOMText.js | 636 ++++++++++++++++++++++++ 4 files changed, 734 insertions(+), 4 deletions(-) create mode 100644 src/directives/findAndReplaceDOMText.js diff --git a/src/components/PDFDocument.vue b/src/components/PDFDocument.vue index 0e83e28..6f98b6a 100644 --- a/src/components/PDFDocument.vue +++ b/src/components/PDFDocument.vue @@ -9,7 +9,7 @@ @pages-reset="fitWidth" > - +
+ +
+