Skip to content

Commit de4be38

Browse files
authored
Merge pull request #104 from LibreSign/chore/custom-pdf-worker
chore: make possible customize pdf worker from Vue side
2 parents 73abe35 + fd5e783 commit de4be38

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ https://www.npmjs.com/package/@libresign/vue-pdf-editor
4141
:init-image-scale = "0.2" <!--The zoom level of the initialized picture defaults to 0.2 times the original size-->
4242
:seal-image-show="true" <!--Whether to show the signed example of the default FALSE-->
4343
:seal-image-hidden-on-save="true" <!--Whether the signed example is hidden by the default FALSE when saving-->
44+
:worker-src=null <!-- URL of pdf.worker -->
4445
@onSave2Upload="【save callback】" <!--Save the callback load: PDFBYTES and FILENAME-->
4546
/>
4647
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@libresign/vue-pdf-editor",
33
"description": "vue2 pdf editor component",
4-
"version": "1.3.3",
4+
"version": "1.3.4",
55
"author": "LibreCode",
66
"private": false,
77
"main": "dist/vue-pdf-editor.umd.js",

src/VuePdfEditor.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ import ImageItem from './Components/Image.vue'
197197
import TextItem from './Components/TextItem.vue'
198198
import Drawing from './Components/Drawing.vue'
199199
import DrawingCanvas from './Components/DrawingCanvas.vue'
200-
import { readAsImage, readAsPDF, readAsDataURL } from './utils/asyncReader.js'
200+
import { configurePDFWorkerSrc, readAsImage, readAsPDF, readAsDataURL } from './utils/asyncReader.js'
201201
import { save } from './utils/PDF.js'
202202
import ImageIcon from 'vue-material-design-icons/Image.vue'
203203
import TextIcon from 'vue-material-design-icons/Text.vue'
@@ -311,7 +311,10 @@ export default {
311311
type: Boolean,
312312
default: false,
313313
},
314-
314+
workerSrc: {
315+
type: String,
316+
default: null
317+
},
315318
},
316319
data() {
317320
return {
@@ -494,6 +497,9 @@ export default {
494497
file = await blob.arrayBuffer();
495498
}
496499
500+
if (this.workerSrc) {
501+
configurePDFWorkerSrc(this.workerSrc)
502+
}
497503
this.pdfDocument = await readAsPDF(file)
498504
if (this.pdfDocument) {
499505
this.numPages = this.pdfDocument.numPages

src/utils/asyncReader.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist'
22
import pdfWorkerCode from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs'
3-
GlobalWorkerOptions.workerSrc = pdfWorkerCode
3+
4+
export function configurePDFWorkerSrc(customWorkerSrc) {
5+
GlobalWorkerOptions.workerSrc = customWorkerSrc || pdfWorkerCode
6+
}
47

58
/**
69
*

0 commit comments

Comments
 (0)