Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gtm-nayan/svelte-pdfjs
https://github.com/gtm-nayan/svelte-pdfjs
pdf pdfjs svelte
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gtm-nayan/svelte-pdfjs
- Owner: gtm-nayan
- License: mit
- Created: 2021-11-03T13:17:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T15:42:00.000Z (3 months ago)
- Last Synced: 2024-12-25T10:08:28.024Z (10 days ago)
- Topics: pdf, pdfjs, svelte
- Language: Svelte
- Homepage: https://gtm-nayan.github.io/svelte-pdfjs
- Size: 1.91 MB
- Stars: 35
- Watchers: 2
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## svelte-pdfjs
A wrapper around Mozilla's PDFJS renderer. Only cares about loading and showing the PDF and nothing else, all the fancy stuff such as styling the viewer is left up to the consumer. Still in early stages so feel free to create an issue or a PR for any bugs that you find, any improvements or feature requests.
## Usage
You'll have to install `pdfjs-dist` and provide a worker to the `Document` component through svelte's context. For vite/sveltekit users a convenience function is exported through [svelte-pdfjs/utils/vite](src/lib/utils/vite.ts) which takes care of browser checks, resolving the url to the worker, setting the context and cleaning up when the component is destroyed.
See [src/routes/+page.svelte](src/routes/+page.svelte) and [src/routes/+layout.svelte](src/routes/+layout.svelte)
[Demo](https://gtm-nayan.github.io/svelte-pdfjs)## SSR
For now this package cannot be used with SSR, contributions to improve in that area are more than welcome. Because of how pdfjs-dist is packaged, there is an eval which prevents bundlers from properly minifying whatever chunk it ends up in. To get around it, you can patch your installation of pdfjs-dist such that all instances of `_is_node.isNodeJs` are replaced with `false` since those parts aren't going to be used anyway.
## TODOs:
- [x] Text layer rendering
- [x] SvelteKit compatibility
- [ ] SVG renderer
- [ ] Annotation layer
- [ ] Error handling
- [ ] Expose more stuff## License
[MIT](LICENSE)