Getting Started

Options

Configure Nuxt PDFMake behavior, routes, devtools, and fonts.

Configure the module with the pdfmake key in nuxt.config.ts.

ts

nuxt.config.ts

export default defineNuxtConfig({
  modules: ["nuxt-pdfmake"],
  pdfmake: {
    enabled: true,
    enableComposable: true,
    enableDevtools: true,
    enableApiRoute: undefined,
    fonts: {
      useDefaultRoboto: true,
    },
  },
});

Core Options

  • enabled (boolean) - Enable or disable the module. Defaults to true.
  • enableComposable (boolean) - Auto-import usePDFMake() for client code and the server utilities for Nitro. Defaults to true.
  • enableDevtools (boolean) - Register the PDFMake panel in Nuxt DevTools. Defaults to true.
  • enableApiRoute (boolean) - Expose POST /_pdfmake/generate. Defaults to enabled in development and disabled in production unless explicitly set to true.

Font Options

Bundle Size Warning
Including many or large custom or Google Fonts can significantly increase your bundle size and memory usage since the module embeds them into the generated virtual font module.

You may have to use the NODE_OPTIONS=--max-old-space-size= environment variable to increase the memory limit for the build process when using many or large fonts.

Fonts are configured under pdfmake.fonts.

ts

nuxt.config.ts

export default defineNuxtConfig({
  pdfmake: {
    fonts: {
      custom: {
        Inter: {
          normal: "./assets/fonts/Inter-Regular.ttf",
          bold: "./assets/fonts/Inter-Bold.ttf",
          italics: "./assets/fonts/Inter-Italic.ttf",
          bolditalics: "./assets/fonts/Inter-BoldItalic.ttf",
        },
      },
      googleFonts: ["Lato", "Open Sans"],
      useDefaultRoboto: false,
    },
  },
});
  • fonts.custom (Record<string, TFontFamilyTypes>) - Local TTF or OTF files resolved at build time from your project root. The module embeds these files into the generated virtual font module so both client and server PDF generation can use them.
  • fonts.googleFonts (string[]) - Google Font family names to download and cache at build time. Downloaded font files are cached in .nuxt/pdfmake-fonts-cache/ and embedded like custom fonts.
  • fonts.cdn (Record<string, TFontFamilyTypes>) - Font descriptors that point at CDN or HTTP URLs. These are passed to pdfmake as URLs. Browser-side generation can fetch them at PDF creation time. Server-side URL font access requires enabling pdfmake URL access policy yourself.
  • fonts.useDefaultRoboto (boolean) - Include pdfmake's default Roboto virtual font files. Defaults to true when no custom, Google, or CDN fonts are configured.

API Route

When enabled, the module exposes POST /_pdfmake/generate. Send a JSON body with a docDefinition object and the route returns a PDF response.

const pdf = await $fetch("/_pdfmake/generate", {
  method: "POST",
  body: {
    docDefinition: {
      content: ["Hello from the API route"],
    },
  },
  responseType: "blob",
});