Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Worker with Vue 3 #104

Open
timpulver opened this issue Aug 20, 2021 · 4 comments
Open

Using Worker with Vue 3 #104

timpulver opened this issue Aug 20, 2021 · 4 comments

Comments

@timpulver
Copy link

I tried to use PdfVuer 2.0.1 with Vue.js 3 to display all pages of a PDF (~25 pages).
Because the loading is quite slow, it became obvious that a web worker should be used. Is there currently a way to use the web worker approach with Vue 3?
I did not find a way to load the worker library from pdfjs-dist and pass it on to the internals of PdfVuer to use the worker.

My component:

<template>
  <div v-if="isLoading">
    <div>Loading Manual</div>
  </div>
  <VuePdf
        :src="pdfData"
        v-for="i in numPages"
        :key="i"
        :id="i"
        :page="i"
        annotation
      >
    </VuePdf>
</template>

<script>
import VuePdf from "pdfvuer/dist/pdfvuer.common.js";
import pdfFile from "../assets/pdfs/My_PDF.pdf";

export default defineComponent({
  components: { VuePdf },
  data() {
    return {
      pdfData: undefined,
      numPages: 0,
      currentPage: 1,
      isLoading: true,
    };
  },
  async mounted() {
    this.$nextTick(() => {
      this.pdfData = VuePdf.createLoadingTask(pdfFile);
      this.pdfData.then((pdf) => {
        this.numPages = pdf.numPages;
        this.isLoading = false;
      });
    });
  },
});
</script>
@arkokoley
Copy link
Owner

arkokoley commented Aug 20, 2021 via email

@timpulver
Copy link
Author

Hi Gaurav,
I was wondering if PdfVuer v2.0.1 might not use a web worker by default, because I see the following message in console:

Warning: Setting up fake worker.

@rzdev
Copy link

rzdev commented Jan 4, 2022

same issue as above, i'm on v.2.0.1 & Vue3 and seeing the same fake worker warning in console.

@rjd22
Copy link

rjd22 commented Jan 13, 2022

I've been working on my own project and don't use pdfvuer but use the source code as inspiration.

To use the web worker properly it needs to be registered to pdfjs. This needs to be done the following way:

import * as pdfjs from 'pdfjs-dist';

import PdfjsWorker from 'file-loader!pdfjs-dist/build/pdf.worker';

pdfjs.GlobalWorkerOptions.workerSrc = PdfjsWorker;

Source: https://github.com/wojtekmaj/react-pdf/blob/ca4453f123af51e2faed39a8a62800901030459a/src/entry.webpack.js

pdfvuer doesn't do this atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants