turbopdf
llms.txt1 starsChanged yesterdayMITView on GitHub
HTML, React, Markdown or a JSON document tree → PDF, with a native Rust engine. No browser, no network, no scripts. Node.js ≥ 20, TypeScript types included. Package: turbopdf. This file is for AI coding assistants. It is the whole API in one page. Full guide: docs/guide.md. - turbopdf.create(string) treats the string as HTML. Markdown always goes through { markdown }. - Pass exactly one source: html, react, markdown or tree. - Nothing is fetched over the network. Remote images,…
The file
We split this llms.txt into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 88
If the JSON has the wrong shape (a missing field, an unknown type), the message gives the line and column.
- Very specific: line 89
If the values are wrong (heading level 9, empty QR…), details is [{ path, code, message }], one entry per problem.
≈ “Common” is an estimate: at least 1 in 5 of the 3,727 llms.txt files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
# TurboPDF
> HTML, React, Markdown or a JSON document tree → PDF, with a native Rust engine. No browser, no network,
> no scripts. Node.js ≥ 20, TypeScript types included. Package: `turbopdf`.
This file is for AI coding assistants. It is the whole API in one page. Full guide: docs/guide.md.
## Rules that are easy to get wrong
- `turbopdf.create(string)` treats the string as **HTML**. Markdown always goes through `{ markdown }`.
- Pass exactly one source: `html`, `react`, `markdown` or `tree`.
- Nothing is fetched over the network. Remote images, stylesheets and fonts are skipped with a warning.
Download them yourself, or pass `data:` URLs or local paths.
- Relative paths are read from `baseDir` (default: the working directory) and never outside it.
- JavaScript in the HTML never runs. Render data into the markup first, or use React.
- Component and tree sizes are in points (1/72 in). CSS lengths are CSS (`px`, `mm`, `em`…).
- Unsupported: WOFF/WOFF2 and web fonts loaded from a URL (use local TTF/OTF files). `float` works for simple cases (columns, a logo or image with text beside it); prefer Flexbox or Grid for layouts.
- Edge runtimes / browsers: `import { init, create } from 'turbopdf/edge'`, `await init(wasm)` once (wasm = `turbopdf/turbopdf.wasm`, its bytes or a URL), then `create()` (React: `init(wasm, { renderToStaticMarkup })` from `react-dom/server`); output with `toUint8Array()` / `toResponse()` (no `save`, no files: fonts as bytes, images as data: URLs).
- Problems are **returned** in `pdf.warnings`, not thrown. Check them, or pass `strict: true` to throw.
## Create
```ts
import turbopdf, { TurboPdfError } from 'turbopdf';
const pdf = await turbopdf.create('<h1>Invoice</h1>'); // HTML
await turbopdf.create({ html, css: 'h1{color:#1d4ed8}', baseDir: './templates' });
await turbopdf.create(<Invoice id={42} />); // React element
await turbopdf.create({ markdown: '# Report\n\n| a | b |\n|---|---|\n| 1 | 2 |' });
await turbopdf.create({ tree }); // JSON tree, types in 'turbopdf/tree'
```
Options (every source): `format` ('A3' | 'A4' | 'A5' | 'Letter' | 'Legal', default A4), `orientation`
('portrait' | 'landscape'), `width`/`height` (custom size), `margin` ('10mm' default; a CSS length, a number of CSS pixels, or { top, right, bottom, left }),
`css`, `header`/`footer` (HTML, `{page}` and `{pages}` are replaced), `fonts` ([{ family, path | data, weight?, style? }]),
`watermark` ('PAID' or { text, color, fontSize, fontWeight, angle }), `title`, `lang`, `bookmarks` (true),
`tagged` (true), `pdfua` (false; needs title and lang), `timeout` (30000 ms), `strict` (false), `signal`, `baseDir`.
## Output
```ts
await pdf.save('out/invoice.pdf');
pdf.toBuffer(); // Buffer
pdf.toStream(); // Node stream (Express: pdf.toStream().pipe(res))
pdf.toResponse({ filename: 'invoice.pdf', disposition: 'attachment' }); // web Response (Next.js, Hono, Bun, Deno)
pdf.pages; // page count
pdf.warnings; // { type, message, path?, page? }[]
const preview = await pdf.preview(); // HTML/CSS: { style, pages: [{ page, width, height, html }], toHtml() }
const fit = await pdf.preview({ scaleToFit: true }); // pages shrink as a whole to fit their container (parent needs a width)
const pngs = await pdf.toPng({ scale: 2 }); // [{ page, save(path), toDataUrl() }]
```
## Components (`turbopdf/components`)
`Document` (title, author, lang, pdfua…), `Page` (size, orientation, margin, header, footer, watermark), `View` (flexbox,
column by default; link, keepTogether, role), `Text`, `Span`, `Link` (href: URL or `#id`), `Heading` (level 1–6),
`Image` (src: path, data URL or bytes; fit, alt), `QR` (value, size, ecc, color, background), `Table` (columns,
repeatHeader, headerStyle, cellStyle, altRowStyle) / `Row` (header) / `Cell` (colSpan), `PageNumber` (format
'{page}/{pages}', target), `PageBreak`, `TableOfContents`, `KeepTogether`, `Spacer`, `Divider`.
```tsx
<Document title="Invoice 42" lang="en">
<Page margin={36} footer={<PageNumber format="Page {page} / {pages}" />}>
<Heading>Invoice 42</Heading>
<Table columns={[{ width: 'auto' }, { width: 80, align: 'right' }]}>
<Row header><Cell><Text>Item</Text></Cell><Cell><Text>Price</Text></Cell></Row>
<Row><Cell><Text>Logo</Text></Cell><Cell><Text>450 €</Text></Cell></Row>
</Table>
<QR value="https://acme.com/pay/42" size={72} alt="Pay online" />
</Page>
</Document>
```
## Document tree (JSON, the format an LLM can emit directly)
```json
{ "type": "document", "version": 1, "meta": { "title": "Hello", "lang": "en" },
"children": [{ "type": "page", "children": [
{ "type": "heading", "level": 1, "content": "Hello" },
{ "type": "text", "content": "Generated by a model." },
{ "type": "image", "src": { "qr": "https://acme.com" }, "style": { "width": 72, "height": 72 } }
]}] }
```
Node types: `view`, `text`, `heading`, `image`, `table`, `page_break`, `page_number`, `table_of_contents`. When the tree is invalid,
`create` throws a `TurboPdfError` with `code: 'invalid_tree'`:
- If the JSON has the wrong shape (a missing field, an unknown type), the `message` gives the line and column.
- If the values are wrong (heading level 9, empty QR…), `details` is `[{ path, code, message }]`, one entry per problem.
## HTML and CSS that work
Selectors: type, class, id, attribute, descendant, `>`, `:first-child`, `:last-child`, `:nth-child()`, `::before`/`::after`.
Properties: `display` block/flex/grid/none, Flexbox, Grid (`fr`, `repeat()`), width/height (min/max), margin, padding, border,
border-radius, background(-color), color, font-*, line-height, text-align, `position: absolute`, `break-before/after/inside`,
`calc()`, `var()`, `@page { size; margin }`, `@media print`, local `@font-face`. Elements: block elements, p, h1–h6, span, b, i,
br, hr, `a href`, `img` (PNG, JPEG, WebP, GIF, SVG), inline `<svg>`, table/thead (header repeats on every page), ul/ol, pre, blockquote.
QR codes: `<img src="qr:TEXT" width="90">`, or `` in Markdown.
Page-break classes: `turbopdf-break-before`, `turbopdf-break-after`, `turbopdf-keep-together`.
Markdown extras: `<!-- pagebreak -->` and `<!-- toc -->`.
## Warnings (`pdf.warnings[].type`)
`overflow`, `moved_to_next_page`, `missing_glyph`, `image_failed`, `stylesheet_failed`, `font_failed`, `broken_link`,
`missing_alt`. Each `message` says how to fix the problem. Feed the messages back to the model and render again.
## Errors (`TurboPdfError.code`)
`invalid_source`, `render_timeout`, `render_failed`, `invalid_tree`, `font_failed`, `not_accessible`, `engine_unavailable`,
`react_not_installed`, `warnings_found` (strict), `aborted`.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

