Getting Started

Setup

Install Nuxt PDFMake and generate your first PDF.

Installation

Install nuxt-pdfmake in your Nuxt project.

Add the module to nuxt.config.ts.

ts

nuxt.config.ts

export default defineNuxtConfig({
  modules: ["nuxt-pdfmake"],
});
Ready
You can now create PDFs in the browser and from Nitro server routes.

Client Usage

Use usePDFMake() in client-side Vue code.

vue

pages/index.vue

<script setup lang="ts">
const downloadPdf = () => {
  const pdfMake = usePDFMake();

  pdfMake
    ?.createPdf({
      content: [
        { text: "Hello from Nuxt PDFMake", fontSize: 18, bold: true },
        "This PDF was generated in the browser.",
      ],
    })
    .download("hello.pdf");
};
</script>

<template>
  <button @click="downloadPdf">Download PDF</button>
</template>

usePDFMake() returns null during server-side rendering. Call it from browser interactions, lifecycle hooks, or client-only code.

Server Usage

Use createPDFBuffer() in Nitro route handlers.

ts

server/api/report.get.ts

export default defineEventHandler(async (event) => {
  const buffer = await createPDFBuffer({
    content: [
      { text: "Server generated PDF", fontSize: 18, bold: true },
      "This PDF was generated in a Nitro route.",
    ],
  });

  setHeader(event, "Content-Type", "application/pdf");
  setHeader(event, "Content-Disposition", 'inline; filename="report.pdf"');

  return buffer;
});