vue-pdf-embed is a Vue 3 component designed for rendering PDF documents within web applications. It leverages PDF.js internally to provide features like controlled rendering, handling password-protected documents, and including interactive text and annotation layers. The current stable version is 2.1.4, released frequently with minor updates and patches, often updating its internal PDF.js dependency. Key differentiators include its simplicity, direct browser usability via unpkg, and lack of additional peer dependencies beyond Vue itself, making it easy to integrate into Vue 3 projects. It explicitly supports only Vue 3; for Vue 2, users must install `vue-pdf-embed@1`. It offers fine-grained control over PDF display, including page rotation, scaling, and selective page rendering.
npm install vue-pdf-embedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to embed a PDF using `VuePdfEmbed`, including importing necessary styles, setting the PDF source, and dynamically controlling page navigation and rotation with reactive Vue refs.
For Vue 2 projects, downgrade to `npm install vue-pdf-embed@1`. For Vue 3, ensure your project is set up for ES Modules and TypeScript if applicable.
Manually import `vue-pdf-embed/dist/styles/annotationLayer.css` and `vue-pdf-embed/dist/styles/textLayer.css` if you need text selection and annotations.
Verify your style imports. Ensure `vue-pdf-embed/dist/styles/*.css` paths are correct. The core styles are now inlined, simplifying basic usage, but text and annotation layers still require explicit imports.
Set the `imageResourcesPath` prop to the correct URL or path with a trailing slash where the annotation layer icons are accessible.
Adjust your CSP to permit the loading of web workers. For example, `worker-src 'self' blob:;` and `script-src 'self' 'unsafe-inline' 'unsafe-eval';` (adjust as per security requirements).
Ensure your project is configured for ES Modules (e.g., using Vite or Webpack 5 with appropriate loaders). The package is ESM-first. Double-check the import path `from 'vue-pdf-embed'`.
Ensure the `VuePdfEmbed` component is mounted within a visible HTML element. Check for any custom CSS that might hide or interfere with the canvas elements. Update to the latest patch version (>=2.1.3) to benefit from canvas styling and null checks fixes.
By default, `vue-pdf-embed` should handle the worker. If you're using an 'essential build' introduced in v2.0.0, you might need to manually set `GlobalWorkerOptions.workerSrc` to the path of the PDF.js worker script. For standard usage, ensure bundler settings allow worker loading.
Verify that `pdfSource` is a valid URL or Base64 string of a correctly formatted PDF. If the PDF is password-protected, use the appropriate prop to provide the password.