Skip to content

Commit

Permalink
Merge pull request #22 from losblancos113/main
Browse files Browse the repository at this point in the history
Add workerSrc prop
  • Loading branch information
afrijaldz authored Sep 25, 2024
2 parents f0cc4d4 + 7f1c1c9 commit 7240806
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@privyid/pdf-ajaib",
"version": "0.1.9",
"version": "0.1.10",
"private": false,
"license": "MIT",
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions src/components/pdf-viewers/PdfViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export default defineComponent({
noNavigation: {
type: Boolean,
default: false,
},
workerSrc: {
type: String,
}
},
emits: ['ready', 'loaded', 'error', 'error-password', 'update:page', 'update:scale'],
Expand Down Expand Up @@ -97,9 +100,9 @@ export default defineComponent({
watchDebounced(
() => [props.src, props.password],
([src, password]) => {
([src, password, workerSrc]) => {
if (src) {
openDoc(src, password)
openDoc(src, password, workerSrc)
}
},
{ debounce: 500 }
Expand All @@ -114,7 +117,7 @@ export default defineComponent({
)
onMounted(async () => {
if (props.src) openDoc(props.src, props.password)
if (props.src) openDoc(props.src, props.password, props.workerSrc)
})
onLoaded((doc) => {
Expand Down
9 changes: 6 additions & 3 deletions src/components/pdf-viewers/utils/use-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export function useViewer(container: Ref<HTMLDivElement>, viewer: Ref<HTMLDivEle
const errorEvent = createEventHook<Error>()
const readyEvent = createEventHook<PDFViewer>()

async function openDoc(url: string, password?: string) {
async function openDoc(url: string, password?: string, workerSrc?: string) {
loading.value = true
error.value = undefined

try {
pdfJS.value = await import('pdfjs-dist')

if (typeof window !== 'undefined' && 'Worker' in window)
pdfJS.value.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfJS.value.version}/build/pdf.worker.min.js`
if (workerSrc) {
pdfJS.value.GlobalWorkerOptions.workerSrc = workerSrc
} else {
pdfJS.value.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfJS.value.version}/build/pdf.worker.min.js`
}

// Close previous document
await closeDoc()
Expand Down

0 comments on commit 7240806

Please sign in to comment.