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/helpersJSX 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.
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:
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
| Task | Guide |
|---|---|
| Generate a PDF in the browser | Runtimes & frameworks |
| Return a PDF from a server route | Runtimes & frameworks |
| Set the page size, orientation, and margins | Page setup |
| Control page breaks and repeated table headers | Pagination |
| Add page numbers, headers, and footers | Headers & footers |
| Load fonts, logos, and photos | Fonts & images |
| Add links, a table of contents, or bookmarks | Links, outline & metadata |
| Create a receipt, certificate, or label | Tickets & receipts, Single-page PDFs |
| Generate archival or accessible output | PDF/A & PDF/UA |
| Embed invoice XML or another file | Attachments |
| Build a complete document | Invoices, Reports & statements, Charts, Tickets & receipts |
| Move from Puppeteer or react-pdf | From Puppeteer, From react-pdf |
| Compare takumi-pdf with other tools | Comparison |
| Look up every option | render() reference |
Last updated on