vue-html2pdf is a Vue.js wrapper component that facilitates client-side PDF generation directly from HTML content within Vue components, leveraging the robust capabilities of the html2pdf.js library internally. The package allows developers to easily convert any Vue component's template or arbitrary HTML element into a downloadable PDF document. Currently, the stable version is 1.8.0. While there isn't a strict release cadence specified, updates address breaking changes and new features. Key differentiators include its simple component-based API, extensive props for controlling PDF quality, format, orientation, and content width, and a comprehensive event system for managing the entire generation lifecycle, including pagination and pre-download hooks. It provides specific integration guidance for Nuxt.js projects and offers fine-grained control over the underlying html2pdf.js library through event arguments.
npm install vue-html2pdfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `VueHtml2pdf` component in a Vue application, trigger PDF generation programmatically, and listen to key lifecycle events like progress and completion.
Review and update all event listeners in your Vue components to use the new event names (`@startPagination`, `@hasDownloaded`, etc.) as per the 1.8.x migration guide.
Set the props `:enable-download="false"` and `:preview-modal="false"` on the `vue-html2pdf` component when implementing custom logic within the `@beforeDownload` event.
For Nuxt.js, ensure the plugin is configured with `mode: 'client'` in `nuxt.config.js` and wrap component usage in `<client-only>` tags in your templates. Example: `<client-only><VueHtml2pdf ...></VueHtml2pdf></client-only>`.
Ensure the `vue-html2pdf` component is present in the DOM and accessible via its ref. If calling immediately, consider wrapping the call in `this.$nextTick(() => this.$refs.html2Pdf.generatePdf())` to ensure the component is mounted.