# vue-pdf-export > `vue-pdf-export` is a vue + TypeScript browser-side HTML-to-PDF package with two rendering modes: high-fidelity Canvas rendering and selectable/searchable vector-text rendering. The project is maintained by Saurabh Choudhary. ## Primary resources - [Live playground](https://vue-pdf-export-playground.vercel.app/) - [npm package](https://www.npmjs.com/package/vue-pdf-export) - [Author portfolio](https://saurabhzaiswal.vercel.app/) - [Feedback / feature requests](https://vue-pdf-export.canny.io/) - [Funding](https://buymeacoffee.com/saurabhzaiswal) - [Documentation Link](https://vue-pdf-export-docs.vercel.app) The source repository is maintained privately. ## Package capabilities ### Core PDF workflow - Browser-side HTML-to-PDF generation - vue component API - Vue composable API - TypeScript declarations - PDF `Blob` output - PDF preview modal - PDF download - Programmatic print - Blob URL cleanup - Safe filename normalization - Shared public API across both render modes ### Rendering modes #### Canvas mode `renderMode="canvas"` - Default package mode for backwards compatibility - Uses `html2pdf.js` + `html2canvas` + `jsPDF` - Best choice when browser/CSS visual fidelity is the priority - Body content is rasterized and is therefore not normally selectable/searchable - Paginated documents with `.html2pdf__page-break` markers use incremental page-by-page Canvas rendering - Canvas documents without page-break markers retain the legacy whole-document html2pdf.js worker Incremental Canvas rendering: - renders one logical PDF page at a time - keeps raster captures page-bounded - removes temporary page DOM after capture - releases canvas backing stores after insertion - reports page-aware progress - yields to the browser between expensive steps - supports cooperative cancellation before subsequent work begins #### Selectable-text mode `renderMode="text"` - Emits real PDF text/vector operations for supported content - Selectable text - Searchable text - Copyable text - Selectable header/footer text - Selectable footer page numbers - Clickable PDF hyperlinks - Images - Backgrounds - Borders - Basic border radius - Text color, weight, italic, decoration, alignment, and spacing - Multi-page output - Manual page breaks - Password protection - PDF permissions - Metadata - Compression - Headers - Footers - Watermarks Selectable-text mode prioritizes real PDF text over pixel-perfect support for every browser CSS feature. ## Pagination - Manual pagination - Automatic height-based pagination - Page-break protection - Custom page-break avoidance selectors - Automatic pagination reset - Manual page breaks remain preserved when automatic pagination is reset - Automatic pagination accounts for selective header spacing Manual page-break marker: ```html
``` Recommended CSS: ```css .html2pdf__page-break { display: block; height: 0; clear: both; } ``` Do not add `break-before` or `page-break-before` to this helper while legacy html2pdf page-break behavior is active because duplicate or blank pages can result. Default page-break protection selectors include: ```text .pdf-keep-together .pdf-no-break img ``` ## Headers - Optional PDF headers - Plain-text header content - Trusted HTML header content with `headerHtml` - Non-empty `headerHtml` takes precedence over `headerText` - Optional header logo via `headerLogoEnabled` - Header images from URL or data URL - Configurable header logo width and height - Aspect-ratio-safe logo rendering - Header background and text colors - Header page targeting - Page-aware header spacing Header targeting supports: ```text all first last except-first number[] ``` Selective header targeting reserves header spacing only on pages that receive the header. Explicit user margins in `htmlToPdfOptions.margin` remain independent. `headerHtml` is trusted developer-controlled HTML and must not contain unsanitized user input. ## Footers - Optional PDF footers - HTML footer mode - Text footer mode - Plain-text footer content - Trusted HTML footer content with `footerHtml` - Non-empty `footerHtml` takes precedence over `footerText` in HTML mode - Optional footer logo via `footerLogoEnabled` - Footer images from URL or data URL - Configurable footer logo width and height - Aspect-ratio-safe logo rendering - Footer background and text colors - Footer page template with `{n}` and `{total}` - Legacy footer compatibility through `useFooterComponent` - Selectable footer text/page numbers in selectable-text mode Footer page numbering uses templates such as: ```text Page {n} of {total} ``` There is no separate dedicated page-numbering API. Footers currently use all-page behavior and do not have independent page targeting. `footerHtml` is trusted developer-controlled HTML and must not contain unsanitized user input. ## Footer performance optimization Static HTML footer content is rasterized once and reused across PDF pages. Dynamic page numbering remains separate and is drawn as jsPDF text. Recorded benchmark fixtures showed: - HTML footer without logo: `7.82 s -> 1.43 s` (~81.7% less time) - HTML footer with logo: `11.81 s -> 1.29 s` (~89.1% less time) - footer-heavy PDF size: `~46.7 MB -> ~1.0 MB` (~97.9% smaller) - footer no-logo peak heap: `102.6 MB -> 26.5 MB` (~74.2% lower) These values belong to the project benchmark fixtures and are not universal package-wide performance guarantees. ## Watermarks - Text watermarks - Image watermarks - Background watermarks - Foreground watermarks - Single watermark mode - Repeated/tiled watermark mode - Opacity - Rotation - Positioning - Spacing - Per-page watermark targeting Watermark page targeting supports: ```text all first last except-first number[] ``` Header targeting and watermark targeting are independent. ## Security - Optional PDF password protection - User/open password - Owner password - Password construction from multiple password parts - Configurable PDF permissions - Direct security props can override raw jsPDF encryption settings - Explicit `security.enabled: false` removes inherited raw encryption Supported permission values: ```ts type PdfPermission = | 'print' | 'modify' | 'copy' | 'annot-forms' ``` `passwordParts` are combined into one final user/open password. They do not create multiple independent valid passwords. PDF permission enforcement is viewer-dependent. ## Encrypted Canvas memory behavior Large encrypted Canvas/raster PDFs can retain substantially more memory than equivalent unencrypted Canvas PDFs in Chromium. The same encrypted-raster retention pattern was reproduced with raw jsPDF outside the Vue component lifecycle. For that reason this behavior is treated as an upstream/dependency concern rather than described as a confirmed Vue memory leak. Upstream tracking: https://github.com/parallax/jsPDF/issues/4017 Practical guidance: - avoid unnecessarily high Canvas scale values - resize oversized images before generation - generate one very large PDF at a time - prefer selectable-text mode when it meets visual requirements - test encrypted long documents on representative target devices - consider splitting exceptionally large documents when browser memory is constrained ## Metadata and compression Metadata supports: - title - author - subject - keywords - creator The direct `metadata` prop takes priority over compatible raw metadata configuration. The package also supports optional jsPDF stream compression. The direct `compress` prop takes priority over compatible raw `htmlToPdfOptions.jsPDF.compress`. Compression does not reduce html2canvas resolution or JPEG quality. ## Links When PDF links are enabled, real `` elements can become clickable PDF annotations. Selectable-text mode keeps link text selectable. ## Progress and loading - Built-in loader - Custom loader slot - Numeric progress updates - Rich progress-stage updates - Page-aware `currentPage` / `totalPages` progress Progress stages: ```text idle pagination images preparing rendering watermark header footer metadata serializing complete error ``` Example `PdfProgressState`: ```ts { stage: 'rendering', progress: 57, currentPage: 21, totalPages: 100 } ``` Progress values represent generation work, not byte-level network transfer progress. ## Cancellation The component exposes: ```ts cancelGeneration(): void ``` Example: ```ts pdfRef.value?.cancelGeneration() ``` Cancellation is cooperative. Incremental Canvas rendering checks cancellation around page capture, encoding, insertion, and browser-yield checkpoints. Selectable-text rendering checks cancellation during DOM walking, image materialization, pagination, and page rendering. Already-running synchronous browser/jsPDF operations cannot be interrupted in the middle; cancellation takes effect at the next safe checkpoint. Cancellation is treated as an expected abort flow rather than a normal package error. Regression tests verify cancellation cleanup and successful generation recovery afterward. ## Repeated-image optimization Selectable-text rendering uses a per-generation cache for repeated real `