Skip to content

how use Web Worker Loading in vite #202

Answered by hrynko
newives asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @newives,

In essence, you just need to install proper versions of vue-pdf-embed and pdfjs-dist as dependencies.

npm i vue-pdf-embed@2 pdfjs-dist@3.11.174

And then import the PdfWorker from pdfjs-dist as a URL (see ?url) and set it to the GlobalWorkerOptions imported from vue-pdf-embed.

<script setup>
import { GlobalWorkerOptions } from 'vue-pdf-embed/dist/index.essential.mjs'
import PdfWorker from 'pdfjs-dist/build/pdf.worker.js?url'

import 'vue-pdf-embed/dist/style/index.css'

GlobalWorkerOptions.workerSrc = PdfWorker

const pdfSource = '<PDF_URL>'
</script>

<template>
  <VuePdfEmbed :source="pdfSource" />
</template>

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nocarroll-v8m
Comment options

@hrynko
Comment options

Answer selected by hrynko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #200 on March 27, 2024 09:37.