Skip to Content
Takumi

Generate PDFs

Install takumi-pdf, render your first PDF from JSX or HTML, and find the guide for your document.

takumi-pdf is takumi's PDF output, for invoices, reports, and other paged documents. Pass JSX, an HTML string, or a node tree, and style it with CSS or Tailwind. The renderer runs in WebAssembly and does not launch a browser.

It shares one layout engine, a port of Chromium's layout, with image output and the paint tree. Each output applies the same layout rules to a template. To turn an HTML file into a PDF without writing code, use the command line instead.

Install

npm i takumi-pdf @takumi-rs/helpers

JSX input also needs react, which supplies the JSX runtime.

Render a document

Save this as invoice.tsx and run bun invoice.tsx to write invoice.pdf. On Node.js, compile the JSX first.

invoice.tsx
import {  } from "takumi-pdf";
import { ,  } from "takumi-pdf/primitives";
import {  } from "@takumi-rs/helpers";
import {  } from "node:fs/promises";

const  = await (
  <>
    <>Invoice 1042</>
    <>Total: $1,290</>
  </>,
  {
    : "a4",
    : await (["Inter"]),
    : (
      < ="flex w-full justify-center text-[10px] text-gray-500">
        Page < /> of < />
      </>
    ),
  },
);

await ("invoice.pdf", );

render() returns a Uint8Array. By default, these hold:

  • Content flows across A4 pages with automatic margins.
  • Text stays selectable, and fonts are embedded as subsets.
  • Text inside an SVG image is drawn as outlines, so it cannot be selected.

An HTML string goes through the same parser as takumi-js. A <style> tag in the string applies only to that render:

Render HTML
import {  } from "takumi-pdf";

const  = await (`
  <style>.total { font-weight: 700 }</style>
  <div><span class="total">Total: $1,290</span></div>
`);

Headers, footers, and measure() take the same inputs.

Find your guide

TaskGuide
Generate a PDF in the browserRuntimes & frameworks
Return a PDF from a server routeRuntimes & frameworks
Set the page size, orientation, and marginsPage setup
Control page breaks and repeated table headersPagination
Add page numbers, headers, and footersHeaders & footers
Load fonts, logos, and photosFonts & images
Add links, a table of contents, or bookmarksLinks, outline & metadata
Create a receipt, certificate, or labelTickets & receipts, Single-page PDFs
Generate archival or accessible outputPDF/A & PDF/UA
Embed invoice XML or another fileAttachments
Build a complete documentInvoices, Reports & statements, Charts, Tickets & receipts
Move from Puppeteer or react-pdfFrom Puppeteer, From react-pdf
Compare takumi-pdf with other toolsComparison
Look up every optionrender() reference

Last updated on