ng2-pdf-viewer: Shouldn't ng2-pdf-viewer use pdf.worker.min.js from pdfjs-dist library?
Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [x] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request
My project has to work without outside download requests, so we had to include our own pdf.worker.min.js. But this aproach can be quite troublesome, since pdf.worker.min.js version can change depending on pdfjs version.
As pdfjs-dist library (which is included in ng2-pdf-viewer dependencies) already comes with its version of pdf.worker.min.js, wouldn’t it be better for ng2-pdf-viewer to use it instead of downloading it from an external source?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 22 (9 by maintainers)
My project has the same limitations. But instead of copying and pasting the
pdf.worker.min.jsinto my own assets folder, I provided them as an angular asset in myangular.json. Perhaps it might help someone. I suppose using this you do not need to care for manual updates in pdfjs-dist anymore. Still, it might be a good idea to stick the version of both libraries to avoid nasty surprises.As documented in the readme, you can provide the following to your pdf-components constructor:
@LAlves91 You can always copy
pdf.worker.min.jsfromnode_modulesto yourassetsfolder before you build and then set it like this https://github.com/VadimDez/ng2-pdf-viewer#set-custom-path-to-the-worker@VadimDez and @nika1001,
The project I work on had a MAJOR problem recently because of this solution: pdfjs-dist isn’t static in ng2-pdf-viewer peer dependencies (pdfjs-dist: “^2.2.228”).
I think this can be seen as an evidence about this solution not being the best aproach to not downloading pdf.worker from an external url.
Best regards.
To make setup and use of this library easier -
pdf.worker.min.jsis getting dowloaded from the CDN in the first place. In this way as a developer you don’t need to copy and pastepdf.worker.min.jsto your assets folder and link it in the code.Hi @htruong24 ,
At the moment, this is how we have declared our PDF dependencies in package.json:
"ng2-pdf-viewer": "5.3.2", "pdfjs-dist": "2.1.266",If your project has the same limitations as mine (application shouldn’t access external links), the trick is using these steps:
Once we followed this steps, all our functionalities which had PDF viewers stabilized.
Best regards!