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

The API version does not match the worker version #9997

Closed
dh627 opened this issue Aug 22, 2018 · 3 comments
Closed

The API version does not match the worker version #9997

dh627 opened this issue Aug 22, 2018 · 3 comments

Comments

@dh627
Copy link

dh627 commented Aug 22, 2018

Hi, I'm trying to generate a PDF from a Unit8Array but am getting the following message & am not sure what it means:

FfomxtAXZDQQEEX5m:1 Uncaught (in promise) UnknownErrorException {name: "UnknownErrorException", message: "The API version "2.0.489" does not match the Worker version "2.0.775".", details: "Error: The API version "2.0.489" does not match the Worker version "2.0.775"."}

here is my code:

import pdfjs from 'pdfjs-dict';

Meteor.call('ideas.export', FlowRouter.getParam('id'), (err, pdf) => templateInstance.pdfArray.set(pdf));

setTimeout(() => {
  console.log(templateInstance.pdfArray.get());
  pdfjs.GlobalWorkerOptions.workerSrc = 'http://mozilla.github.io/pdf.js/build/pdf.worker.js';
  var canvasContainer = document.getElementById('myCanvasContainer');
  var options = options || { scale: 1.5 };

  function renderPage(page) {
      var viewport = page.getViewport(options.scale);
      var canvas = document.createElement('canvas');
      var ctx = canvas.getContext('2d');
      var renderContext = {
        canvasContext: ctx,
        viewport: viewport
      };

      canvas.height = viewport.height;
      canvas.width = viewport.width;
      canvasContainer.appendChild(canvas);

      page.render(renderContext);
  }

  function renderPages(pdfDoc) {
      for(var num = 1; num <= pdfDoc.numPages; num++)
          pdfDoc.getPage(num).then(renderPage);
  }

  pdfjs.disabledWorker = true;
  pdfjs.getDocument(templateInstance.pdfArray.get()).then(renderPages);
  }, 10000)

}

and my package.json:

"ng2-pdf-viewer": "^5.1.1",
"pdfjs-dist": "^2.0.550",
@dh627 dh627 closed this as completed Aug 22, 2018
@dh627 dh627 reopened this Aug 22, 2018
@dh627 dh627 changed the title Uncaught TypeError: pdfjs.getDocument is not a function The API version does not match the worker version Aug 22, 2018
@dh627 dh627 closed this as completed Aug 22, 2018
@wwwhatley
Copy link

Why was this closed?

@make-github-pseudonymous-again
Copy link

make-github-pseudonymous-again commented Feb 4, 2021

Quite literally, the API version does not match the worker version. Use

import pdfjs from 'pdfjs-dist';
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
    const WORKER_URL = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
    pdfjs.GlobalWorkerOptions.workerSrc = WORKER_URL;
}

where the part that says ${pdfjs.version} makes the worker version match the API version.

@igortas

This comment was marked as abuse.

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