API

PDF Styling & data-pdf-ignore

Customize export-only page and body styles, CSS classes, themes and auto-fit behavior, and exclude screen-only elements using 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>
MarkupPDF behavior
data-pdf-ignoreexcluded
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

OptionTypePurpose
enabledbooleanMaster styling switch.
pageBackgroundstringPDF page surface background.
bodyBackgroundstringInner body/content surface background.
pageClassstringExport-only page class names.
bodyClassstringExport-only body class names.
pageStyle`PdfStyle \PdfStyleResolver`
bodyStylePdfStyleStatic body styles.
cssTextstringExport-only scoped CSS text.
stylesheetUrlsstring[]External export stylesheet URLs.
printStylesheetUrlsstring[]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>
VariableBuilt-in UI area
--vue-pdf-preview-width, --vue-pdf-preview-heightDesktop dialog size.
--vue-pdf-preview-mobile-width, --vue-pdf-preview-mobile-heightPreview size at widths up to 640px; defaults fill the viewport.
--vue-pdf-preview-radius, --vue-pdf-preview-backdropDialog corners and modal backdrop.
--vue-pdf-preview-surface, --vue-pdf-preview-colorPreview surface and foreground.
--vue-pdf-preview-close-background, --vue-pdf-preview-close-color, --vue-pdf-preview-focus-colorClose button colors and focus outline.
--vue-pdf-loader-backdrop, --vue-pdf-loader-surface, --vue-pdf-loader-colorLoader overlay, panel and text.
--vue-pdf-loader-radius, --vue-pdf-loader-spinner-track, --vue-pdf-loader-spinner-accentLoader corners and spinner.
--vue-pdf-layout-backgroundOptional 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.

Copyright © 2026