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

Allow to bundle the worker with the app not to need to download it #334

Closed
kuba007 opened this issue Jun 15, 2018 · 3 comments
Closed

Allow to bundle the worker with the app not to need to download it #334

kuba007 opened this issue Jun 15, 2018 · 3 comments
Labels

Comments

@kuba007
Copy link

kuba007 commented Jun 15, 2018

Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [ ] Bug report -> please search issues before submitting
- [x] Feature request
- [x] Documentation issue or request

Based on some network issues, I have added pdfjs-dist to my package.json. Then I found I can set custom path to the worker... Can I use the bundled pdfjs-dist instead of downloading one?

Thank you for reply!

@VadimDez
Copy link
Owner

@kuba007 you can set custom path to the worker like this: https://github.com/VadimDez/ng2-pdf-viewer#set-custom-path-to-the-worker
And regarding bundled pdfjs-dist - i'm not using it only because it causes problems with webpack right now...

@BeatriceThalo
Copy link

BeatriceThalo commented Aug 20, 2018

This solved it for me.

dependencies:
    "@angular/core": "^6.0.0",
    "ng2-pdf-viewer": "^5.0.1",
resolutions:
    "pdfjs-dist": "2.0.489",
    "@types/pdfjs-dist": "^0.1.2"

I'm making a mobile app that can view pdfs offline using the <pdf-viewer> element. I needed to customize the worker path due to cloudflare not being listed in our <meta> content security policy or available offline, but did need to add the following, http: for localhost development, file: for cordova android/ios and electron mac/win/linux.

worker-src http: file:;

Similar to ng2-pdf-viewer itself, my app is also using webpack.
In the client before the component containing the <pdf-viewer> element is constructed:

declare let window: any;
window.pdfWorkerSrc = require('pdfjs-dist/webpack');

I no longer get the error Warning: Setting up fake worker. pdf.js 351 and my own animated loading spinner on the page no longer noticeably freezes/is choppy during the pdf's rendering, indicating that pdf rendering is no longer processing on the UI-thread, but instead on the worker-thread.

I found this solution for webpack users of pdfjs-dist in issue 7612, here.

@stale
Copy link

stale bot commented Jul 31, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 31, 2020
@stale stale bot closed this as completed Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants