Programmatic API
Component methods
| Method | Return | Purpose |
|---|---|---|
generatePdf() | Promise<Blob> | Generate the PDF and return its Blob. |
generatePdfArrayBuffer() | Promise<ArrayBuffer> | Generate once, then serialize the resulting Blob to binary bytes. |
generatePdfBase64(options?) | Promise<string> | Generate once, then return raw Base64 or an optional PDF data URL. |
print() | Promise<void> | Generate/open the native browser print flow. |
closePreview() | void | Close the active preview flow. |
resetPagination() | void | Remove automatically inserted page breaks. |
cancelGeneration() | void | Request cooperative cancellation of active generation. |
interface Html2PdfInstance {
generatePdf: () => Promise<Blob>
generatePdfArrayBuffer: () => Promise<ArrayBuffer>
generatePdfBase64: (options?: PdfBase64Options) => Promise<string>
print: () => Promise<void>
closePreview: () => void
resetPagination: () => void
cancelGeneration: () => void
}
Recommended ref:
const pdfRef = ref<InstanceType<typeof Html2Pdf> | null>(null)
Generate Blob
const blob = await pdfRef.value?.generatePdf()
Blob remains the recommended default for downloads, previews, object URLs, and very large PDFs.
Generate ArrayBuffer
const arrayBuffer = await pdfRef.value?.generatePdfArrayBuffer()
Use ArrayBuffer when you need raw PDF bytes for binary APIs, workers, storage, cryptographic processing, or transports that accept binary data.
Generate Base64
Raw Base64:
const base64 = await pdfRef.value?.generatePdfBase64()
PDF data URL:
const dataUrl = await pdfRef.value?.generatePdfBase64({
dataUrl: true,
})
Base64 is convenient for string-only transports, but it is larger than the binary payload and requires additional conversion memory. Prefer Blob or ArrayBuffer for large PDFs.
The ArrayBuffer and Base64 methods reuse the normal PDF generation flow and serialize the generated Blob. They do not run a second PDF renderer.
For pure programmatic output, disable automatic browser-side download/preview with
:enable-download="false"and:preview-modal="false".
Low-level output serialization
The output helpers are also available directly:
import {
pdfBlobToArrayBuffer,
pdfBlobToBase64,
serializePdfOutput,
} from 'vue-pdf-export'
const bytes = await pdfBlobToArrayBuffer(blob)
const base64 = await pdfBlobToBase64(blob)
const dataUrl = await pdfBlobToBase64(blob, { dataUrl: true })
const output = await serializePdfOutput(blob, 'arraybuffer')
Supported output formats are blob, arraybuffer, and base64.
await pdfRef.value?.print()
Print works through the browser print flow in both Canvas and selectable-text rendering modes.
Close preview
pdfRef.value?.closePreview()
Reset automatic pagination
pdfRef.value?.resetPagination()
This removes only automatically inserted page breaks.
Cancel active generation
pdfRef.value?.cancelGeneration()
cancelGeneration() requests cooperative cancellation of the current export.
- Incremental Canvas rendering checks cancellation around page capture, encoding, insertion, and browser-yield points.
- Selectable-text rendering checks cancellation while walking the DOM, materializing images, paginating, and rendering pages.
- Synchronous browser/jsPDF work such as an already-running
toDataURL()or finalpdf.output('blob')call cannot be interrupted in the middle; cancellation takes effect at the next safe checkpoint. - Cancellation is treated as an expected abort flow and is not emitted as the component's normal
errorevent.
Composable
import { useHtml2Pdf } from 'vue-pdf-export'
const {
loading,
progress,
stage,
progressState,
error,
pdfUrl,
lastResult,
generate,
download,
print,
cleanup,
} = useHtml2Pdf()
Footers
When enabled, the footer is applied to every PDF page. Header-style selective page targeting is not exposed as a separate footer API.
Loader, Progress, Metrics, Events & Slots
Build custom vue-pdf-export UI with loaders, progress state, generation metrics, component events and slots for PDF content and user-defined loading experiences.
