API

Programmatic API

Programmatic API

Component methods

MethodReturnPurpose
generatePdf()Promise<Blob>Generate the PDF and return its Blob.
print()Promise<void>Generate/open the print flow.
closePreview()voidClose the active preview flow.
resetPagination()voidRemove automatically inserted page breaks.
cancelGeneration()voidRequest 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()

Print

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 final pdf.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 error event.

Composable

import { useHtml2Pdf } from 'vue-pdf-export'

const {
  loading,
  progress,
  stage,
  progressState,
  error,
  pdfUrl,
  lastResult,
  generate,
  download,
  print,
  cleanup,
} = useHtml2Pdf()
Copyright © 2026