Getting Started
Options
Configure Nuxt PDFMake behavior, routes, devtools, and fonts.
Configure the module with the pdfmake key in nuxt.config.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 totrue.enableComposable(boolean) - Auto-importusePDFMake()for client code and the server utilities for Nitro. Defaults totrue.enableDevtools(boolean) - Register the PDFMake panel in Nuxt DevTools. Defaults totrue.enableApiRoute(boolean) - ExposePOST /_pdfmake/generate. Defaults to enabled in development and disabled in production unless explicitly set totrue.
Font Options
fonts.custom or fonts.googleFonts can significantly increase your bundle size and memory usage since the module embeds them into the generated virtual font module. Fonts from fonts.nuxtFonts and fonts.cdn are not embedded.
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.
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"],
nuxtFonts: false,
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.nuxtFonts(boolean) - Import every family resolved by@nuxt/fonts. Defaults tofalse. Browser font files are fetched only when PDFMake generates a PDF; Nitro packages the same resolved files as server assets. Nuxt Fonts descriptors take precedence when a family name also exists incustom,googleFonts, orcdn.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 totruewhen no custom, Google, or CDN fonts are configured. Families resolved by@nuxt/fontsdon't count, so set it tofalseexplicitly if you don't want Roboto registered alongside them.
Nuxt Fonts Integration
@nuxt/fonts is an optional peer dependency (v1.0.0 or newer). Install it, register it in modules, then opt in with pdfmake.fonts.nuxtFonts. The module throws a build error if the option is on and @nuxt/fonts is missing.
nuxt.config.ts
export default defineNuxtConfig({
modules: ["@nuxt/fonts", "nuxt-pdfmake"],
fonts: {
families: [
{
name: "Inter",
global: true,
weights: [400, 700],
styles: ["normal", "italic"],
},
],
},
pdfmake: {
fonts: {
nuxtFonts: true,
},
},
});
Use global: true for fonts used only inside PDFs. Production builds resolve every family referenced by your CSS plus all global families before Nitro is built. In development, @nuxt/fonts resolves families lazily as CSS is requested, and this module packages them once when Nitro starts, so mark PDF fonts global: true and restart the dev server after changing font config.
PDFMake's font parser cannot subset WOFF2 files, which is what @nuxt/fonts serves by default. Without a fix, PDF generation fails with RangeError: Offset is outside the bounds of the DataView or renders broken glyphs. So when nuxtFonts is on and you haven't set fonts.defaults.formats, the module sets it to ["woff"] for you. A formats value you set yourself, globally or on a family, always wins.
nuxt.config.ts
fonts: {
// Optional: pick TTF/OTF/WOFF explicitly instead of the WOFF default
defaults: { formats: ["ttf"] },
},
When a face offers several formats the module prefers TTF/OTF, then WOFF, and it logs a build warning if a family ends up with WOFF2 only. The WOFF default applies to every family @nuxt/fonts handles, so your site's own web fonts are served as WOFF too (slightly larger than WOFF2). Set formats: ["woff2"] on a site-only family to keep WOFF2 for it.
Faces served from a remote http(s) URL are passed to pdfmake as-is instead of being packaged. In the browser that works out of the box; on the server it needs pdfmake's URL access policy (setUrlAccessPolicy(() => true)), the same as fonts.cdn.
PDFMake supports four font slots. The module selects the nearest resolved 400/700 normal/italic faces, accepts oblique as italic, and falls back to another available face when a slot is missing. Variable fonts can back multiple slots. When @nuxt/fonts produces several Unicode subset files, the Latin-compatible subset is preferred because PDFMake cannot cascade multiple subset files into one slot.
The browser loads a small descriptor manifest in the background (a failed request logs a warning instead of breaking your app) and pdfmake fetches the selected font URLs only when generating a PDF. Nitro packages the resolved binaries as server assets and registers them (base64-encoded, like embedded fonts) at server startup so useServerPDFMake() remains synchronous. When using app.cdnURL, ensure the CDN permits cross-origin font requests.
API Route
When enabled, the module exposes POST /_pdfmake/generate. Send a JSON body with a docDefinition object and the route returns the PDF with Content-Type: application/pdf. A body without a docDefinition object gets a 400 response.
const pdf = await $fetch("/_pdfmake/generate", {
method: "POST",
body: {
docDefinition: {
content: ["Hello from the API route"],
},
},
responseType: "blob",
});
enableApiRoute: true for production, protect it with your own authentication or rate limiting.DevTools Panel
enableDevtools registers a PDFMake tab in Nuxt DevTools during development only. See Devtools for what the panel shows.