Skip to content

Commit

Permalink
Merge pull request #104 from LibreSign/chore/custom-pdf-worker
Browse files Browse the repository at this point in the history
chore: make possible customize pdf worker from Vue side
  • Loading branch information
vitormattos authored Oct 28, 2024
2 parents 73abe35 + fd5e783 commit de4be38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ https://www.npmjs.com/package/@libresign/vue-pdf-editor
:init-image-scale = "0.2" <!--The zoom level of the initialized picture defaults to 0.2 times the original size-->
:seal-image-show="true" <!--Whether to show the signed example of the default FALSE-->
:seal-image-hidden-on-save="true" <!--Whether the signed example is hidden by the default FALSE when saving-->
:worker-src=null <!-- URL of pdf.worker -->
@onSave2Upload="【save callback】" <!--Save the callback load: PDFBYTES and FILENAME-->
/>
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/VuePdfEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -311,7 +311,10 @@ export default {
type: Boolean,
default: false,
},
workerSrc: {
type: String,
default: null
},
},
data() {
return {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/utils/asyncReader.js
Original file line number Diff line number Diff line change
@@ -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
}

/**
*
Expand Down

0 comments on commit de4be38

Please sign in to comment.