API
Programmatic API
Programmatic API
Component methods
| Method | Return | Purpose |
|---|---|---|
generatePdf() | Promise<Blob> | Generate the PDF and return its Blob. |
print() | Promise<void> | Generate/open the print flow. |
closePreview() | void | Close the active preview flow. |
resetPagination() | void | Remove automatically inserted page breaks. |
cancelGeneration() | void | Request cooperative cancellation of active generation. |
Component methods:
interface Html2PdfInstance {
generatePdf: () => Promise<Blob>
print: () => Promise<void>
closePreview: () => void
resetPagination: () => void
cancelGeneration(): => void
}
Recommended ref:
const pdfRef = ref<InstanceType<typeof Html2Pdf> | null>(null)
Generate
const blob = await pdfRef.value?.generatePdf()
await pdfRef.value?.print()
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()
