svelte-pdfjs is a wrapper around Mozilla’s PDFJS renderer. Its main purpose is to load and display PDF documents, leaving the styling and viewer customization to the user. Although it is still in its early stages, any bugs, improvements, or feature requests are welcome through creating an issue or a PR.
To use svelte-pdfjs, you need to follow these steps:
npm install pdfjs-dist
import { vitePDFWorker } from 'svelte-pdfjs/utils/vite';
import { Document } from 'svelte-pdfjs';
// Resolve the worker URL and set the context
const workerURL = await vitePDFWorker();
<Document worker={workerURL} />
For SSR compatibility, contributions to improve in that area are welcome as the package currently does not support SSR.
To address the bundler issue with pdfjs-dist, you can patch your installation by replacing all instances of _is_node.isNodeJs with false. This step ensures proper minification for the chunk containing pdfjs-dist.
svelte-pdfjs is a lightweight library that simplifies the loading and display of PDF documents in Svelte applications. It provides flexibility for customization while leaving the viewer styling to the user. The library is still in its early stages, but it offers convenient features and welcomes community contributions for bug fixes, improvements, and new features.