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

Is there a way to spawn multiple workers at once to render different PDFs? #16871

Closed
c-x-g opened this issue Aug 24, 2023 · 2 comments
Closed

Comments

@c-x-g
Copy link

c-x-g commented Aug 24, 2023

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: FireFox 116.0.3-1
  • Operating system and its version: Arch Linux 6.1.46-1-lts
  • PDF.js version: 3.9.179
  • Is a browser extension: No

Steps to reproduce the problem:

  1. I'm trying to render images of PDFs on a webpage and with my current implementation they can only be rendered in single-file synchronously; please see GIF below for an illustration:

Peek 2023-08-24 11-12

What is the expected behavior? (add screenshot)
Desired behavior is rendering of images asynchronously so that the bottleneck is the most detailed PDF image to be rendered

What went wrong? (add screenshot)
Loading is slower than I like, particularly if eventually I may want to load a lot more PDFs, is there a way to spawn simultaneous workers to speed up the process?

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

@Snuffleupagus
Copy link
Collaborator

[...] please see GIF below for an illustration:

Unfortunately that's not really helpful, please see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.


Loading is slower than I like, particularly if eventually I may want to load a lot more PDFs, is there a way to spawn simultaneous workers to speed up the process?

By default, unless you manually set certain options, each getDocument-call will use its own worker-thread.

@c-x-g
Copy link
Author

c-x-g commented Aug 24, 2023

Thanks for the reply, yesterday I ran into an issue initially with asynchronous code where the browser would give an error: Cannot use the same canvas during multiple render() operations; possibly the same issue here

After reading some docs it appeared that if a worker was currently in the rendering process of a PDF, it would need to be waited upon for completion before the next PDF could begin. Unfortunately I don't think I can reproduce this issue now which is strange, but I implemented a solution afterward to force an array of file names to render one after another using callbacks and this is where the performance bottleneck for this issue I raised came about.

I removed the callback logic just now and this time I no longer got the issue from the first paragraph above and it appears to be working as expected, I'm not sure what I did wrong previously.

I'll close this as resolved, in particular I had confusion with how to set the workerSrc, but I found this comment helpful

Peek 2023-08-24 11-22

@c-x-g c-x-g closed this as completed Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants