Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdfjs error : The API version "2.16.105" does not match the Worker version "3.1.34".'

Tags:

pdfjs-dist

When I try to use pdfjs in vue for review PDFfile, I get this error. Can anyone tell me how to solve this?

Here is my code:

const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.js')


pdfjsLib.GlobalWorkerOptions.workerSrc =
      'https://mozilla.github.io/pdf.js/build/pdf.worker.js'
    pdfjsLib
      .getDocument("../assets/pdf/活動切結書.pdf'")
      .promise.then((doc) => {
        console.log(doc)
      })

https://support.neat.com/neatapp/error-the-api-version-does-not-match-the-worker-version

I find this solution, that says to clear your browser's cookies. I have done this, but it doesn't get rid of my error.

like image 541
呂玟諠 Avatar asked Sep 19 '25 13:09

呂玟諠


1 Answers

If you use a local pdf.js from your dependency, use the pdf.worker.js from the same dependency. If you want to use files hosted online by mozilla.github.io, both pdf.js and pdf.worker.js should use the online one.

The PDF.js use web worker, the main thread bundle is pdf.js, the web worker bundle is pdf.worker.js, they must collaborate with each other to make thing done. If the build versions of the two bundles do not match, there is a high chance that they will not align with each other.

The matched version rule check avoiding spending lot of time to trace bugs caused by such situation. If you are sure that you use exactly same version, but still get such error, try to clear browser cache, the web browser normally will cache JavaScript file request.

like image 180
Priestch Avatar answered Sep 23 '25 07:09

Priestch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!