PDF Styling & data-pdf-ignore
Exclude content from the PDF
Use data-pdf-ignore for controls, helper UI, debug panels, buttons, or any subtree that should stay visible in the application but not appear in the generated PDF.
<div>
<h1>Invoice</h1>
<button data-pdf-ignore>
Edit invoice
</button>
<aside data-pdf-ignore="true">
This entire subtree is excluded from the PDF.
</aside>
<p data-pdf-ignore="false">
Explicit false keeps this content in the PDF.
</p>
</div>
| Markup | PDF behavior |
|---|---|
data-pdf-ignore | excluded |
data-pdf-ignore="true" | excluded |
data-pdf-ignore="false" | included |
Ignored content is removed only from the temporary export copy and is also excluded from export pagination measurements.
Export-only styling
import type {
PdfPageContext,
PdfStyle,
PdfStylingOptions,
} from 'vue-pdf-export'
const bodyStyle: PdfStyle = {
padding: '16px',
fontSize: '14px',
color: '#17324A',
}
const styling: PdfStylingOptions = {
enabled: true,
pageBackground: '#FFF8E7',
bodyBackground: '#F8FAFC',
pageClass: 'invoice-page',
bodyClass: 'invoice-body',
pageStyle: ({ pageNumber }: PdfPageContext) => ({
padding: '24px',
border: '2px solid #DCE7E9',
borderRadius: '12px',
backgroundColor: pageNumber === 1 ? '#FFF7ED' : '#FFFFFF',
}),
bodyStyle,
cssText: `
.invoice-title {
font-size: 28px;
letter-spacing: -0.02em;
}
.screen-only {
display: none;
}
`,
printStylesheetUrls: [
'/pdf/invoice-print.css',
],
theme: 'light',
autoFit: {
enabled: true,
minScale: 0.6,
maxScale: 1,
allowUpscale: false,
},
}
<Html2Pdf :styling="styling">
<template #pdf-content>
<article>
<h1 class="invoice-title">Invoice</h1>
<button class="screen-only">Application action</button>
</article>
</template>
</Html2Pdf>
Styling options
| Option | Type | Purpose |
|---|---|---|
enabled | boolean | Master styling switch. |
pageBackground | string | PDF page surface background. |
bodyBackground | string | Inner body/content surface background. |
pageClass | string | Export-only page class names. |
bodyClass | string | Export-only body class names. |
pageStyle | `PdfStyle \ | PdfStyleResolver` |
bodyStyle | PdfStyle | Static body styles. |
cssText | string | Export-only scoped CSS text. |
stylesheetUrls | string[] | External export stylesheet URLs. |
printStylesheetUrls | string[] | External print/export stylesheet URLs. |
theme | `'current' \ | 'light' \ |
autoFit | `boolean \ | PdfAutoFitOptions` |
Temporary export styles, themes, stylesheets, and staging DOM are cleaned up after generation.
Customize the built-in preview and loader
In the current documentation version, the built-in preview and loader inherit --vue-pdf-* CSS variables from an ancestor of <Html2Pdf>. They have defaults, so theming is optional. These variables style package UI; they do not style the content inside #pdf-content or the generated PDF. Use your document CSS and the styling option above for the exported pages.
<script setup lang="ts">
import { ref } from 'vue'
import { Html2Pdf } from 'vue-pdf-export'
import 'vue-pdf-export/style.css'
const pdfRef = ref<InstanceType<typeof Html2Pdf> | null>(null)
</script>
<template>
<div class="report-export">
<button type="button" @click="pdfRef?.generatePdf()">Preview PDF</button>
<Html2Pdf ref="pdfRef" preview-modal :enable-download="false" manual-pagination>
<template #pdf-content>
<article><h1>My report</h1><p>Content from my Vue app.</p></article>
</template>
</Html2Pdf>
</div>
</template>
<style>
.report-export {
--vue-pdf-preview-width: 900px;
--vue-pdf-preview-surface: #f8fafc;
--vue-pdf-preview-close-background: #17324a;
--vue-pdf-preview-focus-color: #0b9668;
--vue-pdf-loader-surface: #f8fafc;
--vue-pdf-loader-spinner-accent: #0b9668;
}
</style>
| Variable | Built-in UI area |
|---|---|
--vue-pdf-preview-width, --vue-pdf-preview-height | Desktop dialog size. |
--vue-pdf-preview-mobile-width, --vue-pdf-preview-mobile-height | Preview size at widths up to 640px; defaults fill the viewport. |
--vue-pdf-preview-radius, --vue-pdf-preview-backdrop | Dialog corners and modal backdrop. |
--vue-pdf-preview-surface, --vue-pdf-preview-color | Preview surface and foreground. |
--vue-pdf-preview-close-background, --vue-pdf-preview-close-color, --vue-pdf-preview-focus-color | Close button colors and focus outline. |
--vue-pdf-loader-backdrop, --vue-pdf-loader-surface, --vue-pdf-loader-color | Loader overlay, panel and text. |
--vue-pdf-loader-radius, --vue-pdf-loader-spinner-track, --vue-pdf-loader-spinner-accent | Loader corners and spinner. |
--vue-pdf-layout-background | Optional visible fixed export layout background. |
The preview uses a native dialog: Escape or its labeled close button closes it, focus returns to the previous control, and the dialog fills the mobile viewport by default. The default loader exposes status and bounded progress values and stops its spinner when reduced motion is requested. These controls support keyboard use, but you should still test your document markup and the browser's PDF viewer with your target assistive technology. Replace the default loader with the #loader slot if your app needs different UI.
TypeScript
Use the TypeScript declarations and public types shipped by vue-pdf-export for PDF outputs, component options, events, headers, footers and watermark configuration.
API Reference
Public vue-pdf-export component props, methods, events, slots, composable and types, with links to detailed guides.
