diff --git a/README.md b/README.md index ccd2278..c9634b2 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ https://www.npmjs.com/package/@libresign/vue-pdf-editor :init-image-scale = "0.2" :seal-image-show="true" :seal-image-hidden-on-save="true" + :worker-src=null @onSave2Upload="【save callback】" /> ``` diff --git a/package.json b/package.json index 63c507d..dae0954 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@libresign/vue-pdf-editor", "description": "vue2 pdf editor component", - "version": "1.3.3", + "version": "1.3.4", "author": "LibreCode", "private": false, "main": "dist/vue-pdf-editor.umd.js", diff --git a/src/VuePdfEditor.vue b/src/VuePdfEditor.vue index 71cb4f6..b415cc3 100644 --- a/src/VuePdfEditor.vue +++ b/src/VuePdfEditor.vue @@ -197,7 +197,7 @@ import ImageItem from './Components/Image.vue' import TextItem from './Components/TextItem.vue' import Drawing from './Components/Drawing.vue' import DrawingCanvas from './Components/DrawingCanvas.vue' -import { readAsImage, readAsPDF, readAsDataURL } from './utils/asyncReader.js' +import { configurePDFWorkerSrc, readAsImage, readAsPDF, readAsDataURL } from './utils/asyncReader.js' import { save } from './utils/PDF.js' import ImageIcon from 'vue-material-design-icons/Image.vue' import TextIcon from 'vue-material-design-icons/Text.vue' @@ -311,7 +311,10 @@ export default { type: Boolean, default: false, }, - + workerSrc: { + type: String, + default: null + }, }, data() { return { @@ -494,6 +497,9 @@ export default { file = await blob.arrayBuffer(); } + if (this.workerSrc) { + configurePDFWorkerSrc(this.workerSrc) + } this.pdfDocument = await readAsPDF(file) if (this.pdfDocument) { this.numPages = this.pdfDocument.numPages diff --git a/src/utils/asyncReader.js b/src/utils/asyncReader.js index 32e2f24..9405bde 100644 --- a/src/utils/asyncReader.js +++ b/src/utils/asyncReader.js @@ -1,6 +1,9 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist' import pdfWorkerCode from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs' -GlobalWorkerOptions.workerSrc = pdfWorkerCode + +export function configurePDFWorkerSrc(customWorkerSrc) { + GlobalWorkerOptions.workerSrc = customWorkerSrc || pdfWorkerCode +} /** *