Skip to content
@pyreon/document
fundamentals · documents

Write the report once. Send it as a PDF, a spreadsheet or a Slack message.

Build invoices, reports and notifications from JSX, then render the same tree to any of 20 formats, from PDF and Word to Teams cards and Notion blocks. Text formats need nothing else; PDF, Word, Excel and PowerPoint use an engine you install only if you emit them.

bun add @pyreon/document
Documentation
formats
20 built in16 text formats; PDF, DOCX, XLSX and PPTX via an optional peer.
building blocks
18 primitivesJSX, h(), direct calls or a fluent builder. Same output.
safe output
links allowlisted, CSV formula-safeA javascript: link never reaches HTML, email, Markdown or chat output.
throughput
45.9K–505K small docs/s16 formats, overnight run, one run, author-run.
One document tree rendered to PDF, a spreadsheet, Slack and Markdown An invoice written once as JSX: <Document> with a <Heading> and a <Table>. render(doc, format) is called with 'pdf', then 'xlsx', then 'slack', then 'md', and each time the same tree lights up a different output: a PDF page, a spreadsheet grid, a Slack Block Kit message and a Markdown file. @PYREON/DOCUMENT · ONE TREE, ANY FORMAT const doc = ( <Document> <Heading>Invoice 42</…> <Table rows={lines} /> </Document>) render(doc, 'pdf')'xlsx')'slack')'md') PDF XLSX Slack Markdown # Invoice 42 | item | qty | total | | ---- | --- | ----- | 20 formats · pdfmake, docx, exceljs load only when you emit them
  • 20 output formats from one tree, PDF to Google Chatpackages/fundamentals/document/src/render.ts (20 registerRenderer calls); all 20 rendered in scratch doc1.tsx
  • 18 primitives: Document, Page, Heading, Text, Table, List, Button and morepackages/fundamentals/document/src/index.ts (nodes exports)
  • 45.9K–505K small documents rendered per second across 16 formats (overnight run, one run)00-brief/BENCHMARKS-2026-11-05.md §11

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

One template instead of one per format.

  1. Twenty outputs, one tree

    The same invoice becomes a PDF attachment, an email body, a Markdown file and a Slack message. Change a heading once. Your own components work inside the tree.

  2. Install only what you emit

    pdfmake, docx, exceljs and pptxgenjs are optional peers, imported the first time you render that format. An app that only sends email never installs them, and a missing one fails with the exact bun add command.

  3. User text stays text

    Link and image URLs go through an allowlist, CSV cells starting with =, +, - or @ are neutralised, Markdown text is escaped, and a Slack link cannot smuggle in <!channel>.

  4. Every channel speaks its own format

    Slack gets Block Kit, Teams an Adaptive Card, Notion blocks, Confluence and Jira ADF, Telegram HTML, email a 600px table layout with Outlook-safe buttons.

the difference

Three formats used to mean three templates.

pdfmake + hand-built Slack + CSV

Each format has its own shape, so one report is three templates to keep in step. The CSV breaks on a value like $1,000 and passes =HYPERLINK(…) straight to Excel.

import type { TDocumentDefinitions } from 'pdfmake/interfaces'

const rows = [['US', '$1M'], ['EU', '$800K']]

// PDF: pdfmake's document definition
const pdf: TDocumentDefinitions = {
  info: { title: 'Q4 Report' },
  content: [
    { text: 'Sales report', style: 'header' },
    'Q4 2026 performance summary.',
    { table: { headerRows: 1, body: [['Region', 'Revenue'], ...rows] } },
  ],
  styles: { header: { fontSize: 22, bold: true } },
}

// Slack: Block Kit, by hand
const slack = {
  blocks: [
    { type: 'header', text: { type: 'plain_text', text: 'Sales report' } },
    { type: 'section', text: { type: 'mrkdwn', text: 'Q4 2026 performance summary.' } },
    { type: 'section', text: { type: 'mrkdwn', text: rows.map(([r, v]) => `*${r}*: ${v}`).join('\n') } },
  ],
}

// CSV: escaping is on you
const csv = [['Region', 'Revenue'], ...rows].map((r) => r.join(',')).join('\n')
with @pyreon/document

One component. Pick the format at the call site.

import { Document, Page, Heading, Text, Table, render } from '@pyreon/document'

const rows: [string, string][] = [['US', '$1M'], ['EU', '$800K']]
const Report = (props: { rows: [string, string][] }) => (
  <Document title="Q4 Report">
    <Page>
      <Heading>Sales report</Heading>
      <Text>Q4 2026 performance summary.</Text>
      <Table columns={['Region', 'Revenue']} rows={props.rows} />
    </Page>
  </Document>
)
const report = <Report rows={rows} />

await render(report, 'pdf')    // Uint8Array (with pdfmake installed)
await render(report, 'slack')  // Block Kit JSON
await render(report, 'csv')    // quoted, formula-safe
await render(report, 'email')  // table layout, Outlook-safe buttons
coming from

Coming from pdfmake?

A document definition becomes components

pdfmake
import pdfMake from 'pdfmake/build/pdfmake'
import pdfFonts from 'pdfmake/build/vfs_fonts'
import type { TDocumentDefinitions } from 'pdfmake/interfaces'

pdfMake.addVirtualFileSystem(pdfFonts) // Roboto, the default font, as base64

const rows = [['US', '$1M'], ['EU', '$800K']]

const pdf: TDocumentDefinitions = {
  info: { title: 'Q4 Report' },
  content: [
    { text: 'Sales report', style: 'header' },
    'Q4 2026 performance summary.',
    { table: { headerRows: 1, body: [['Region', 'Revenue'], ...rows] } },
  ],
  styles: { header: { fontSize: 22, bold: true } },
}

pdfMake.createPdf(pdf).download('q4.pdf')
Pyreon

pdfmake still draws the PDF: keep it installed. The extension on the file name picks the format, so q4.docx or q4.md works the same way.

import { Document, Page, Heading, Text, Table, download } from '@pyreon/document'

const rows: [string, string][] = [['US', '$1M'], ['EU', '$800K']]

await download(
  <Document title="Q4 Report">
    <Page>
      <Heading>Sales report</Heading>
      <Text>Q4 2026 performance summary.</Text>
      <Table columns={['Region', 'Revenue']} rows={rows} />
    </Page>
  </Document>,
  'q4.pdf',
)
try it

Same document, different formats.

One tree, rendered live with render() in your browser: HTML, Markdown, CSV, Slack, email and JSON. PDF shows what a real app downloads.

all 20 formats
  • html
  • pdf
  • docx
  • xlsx
  • pptx
  • email
  • md
  • text
  • csv
  • svg
  • json
  • jsonl
  • slack
  • teams
  • discord
  • telegram
  • notion
  • confluence
  • whatsapp
  • google-chat

Binary formats load their library on first use: this button fetches pdfmake, renders the same tree and saves it.

what's included

Documents for every channel.

  • render(node, format, options) typed per format: Uint8Array for the four binary ones, string for the rest.
  • createDocument() a fluent builder with 20 to* methods, from toPdf() to toJsonl().
  • Your components components that return primitives are resolved before rendering; fragments flatten.
  • Email that survives Outlook 600px table layout, inline styles, VML buttons for Outlook.
  • Chat payloads Slack Block Kit, Teams Adaptive Card, Discord, Telegram, WhatsApp, Google Chat.
  • Workspace formats Notion blocks and Atlassian Document Format for Confluence and Jira.
  • json and jsonl a round-trippable tree, or one content block per line for ingestion and chunking.
  • download(doc, "report.pdf") renders and saves in the browser; the extension picks the format.
  • Right to left direction: 'rtl' in HTML, SVG, email and DOCX.
  • registerRenderer() add your own format next to the built-in 20.
recipes

Things to build with it.

An invoice as a PDF attachment and an email body

One component, two renders, one sendMail from whatever mailer you use. The email gets a Pay button that works in Outlook.

import { Document, Page, Heading, Text, Table, Button, render } from '@pyreon/document'

declare function sendMail(m: { to: string; subject: string; html: string; attachments: { filename: string; content: Uint8Array }[] }): Promise<void>
type Line = { item: string; qty: number; price: string }
const Invoice = (props: { no: string; customer: string; lines: Line[]; payUrl: string }) => (
  <Document title={`Invoice ${props.no}`}>
    <Page>
      <Heading>Invoice {props.no}</Heading>
      <Text>Billed to {props.customer}</Text>
      <Table columns={['Item', 'Qty', 'Price']} rows={props.lines.map((l) => [l.item, l.qty, l.price])} striped />
      <Button href={props.payUrl}>Pay now</Button>
    </Page>
  </Document>
)
async function sendInvoice(no: string, customer: string, email: string, lines: Line[]) {
  const doc = <Invoice no={no} customer={customer} lines={lines} payUrl={`https://pay.example.com/${no}`} />
  await sendMail({
    to: email,
    subject: `Invoice ${no}`,
    html: await render(doc, 'email'),
    attachments: [{ filename: `invoice-${no}.pdf`, content: await render(doc, 'pdf') }],
  })
}
Export buttons in the browser

The file extension chooses the format. XLSX and PDF load their engine on the first click.

import { download } from '@pyreon/document'

// `report` is any document tree, e.g. <Report rows={rows} />
const ExportButtons = () => (
  <div>
    <button onClick={() => download(report, 'q4.xlsx')}>Excel</button>
    <button onClick={() => download(report, 'q4.pdf')}>PDF</button>
    <button onClick={() => download(report, 'q4.md')}>Markdown</button>
  </div>
)
A weekly summary in Slack

The slack output is a Block Kit payload an incoming webhook accepts as is.

import { Document, Heading, Text, Link, render } from '@pyreon/document'

async function postWeekly(webhookUrl: string, signups: number, churned: number) {
  const summary = (
    <Document>
      <Heading>Weekly numbers</Heading>
      <Text>{signups} sign-ups, {churned} cancellations.</Text>
      <Link href="https://dash.example.com/weekly">Open the dashboard</Link>
    </Document>
  )
  await fetch(webhookUrl, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: await render(summary, 'slack'),
  })
}
api

Render, build, extend.

Every export has a reference page with its signature, an example and the mistakes people make with it.

render · 6
  • render
  • download
  • createDocument
  • registerRenderer
  • unregisterRenderer
  • isDocNode
layout · 8
  • Document
  • Page
  • PageBreak
  • Section
  • Row
  • Column
  • Spacer
  • Divider
content · 10
  • Heading
  • Text
  • Image
  • Link
  • Button
  • Code
  • Quote
  • List
  • ListItem
  • Table
types · 6
  • DocNode
  • OutputFormat
  • BinaryOutputFormat
  • TextOutputFormat
  • RenderOptions
  • DocumentRenderer
good to know

Good to know before you start.

Binary formats need their engine

Install pdfmake, docx, exceljs or pptxgenjs for PDF, DOCX, XLSX or PPTX. They load on first use; render on the server if you would rather not ship them to browsers.

A render is a snapshot

Signals in the tree are read once. Render again to pick up new values.

Table cells are plain values

Each cell is a string or a number. Put rich content in the blocks around the table.

Formats differ in what they can show

Slack shows a table as a code block, WhatsApp as pipe-separated lines, and chat formats turn a page break into a divider; each renderer does the closest thing its platform has. Check a chat payload in the platform's preview before you rely on it.

Web and server only

Rendering runs in browsers, Node and Bun, not inside iOS or Android apps. Build the file on a server and fetch it, or hand it to the share sheet.

questions

What people ask first.

Do I pay for pdfmake if I only send email?

No. The four binary engines are optional peer dependencies and are imported only when you render their format. If you never render a PDF, pdfmake is never installed or bundled.

Is it safe to render user content?

That is the default. URLs are allowlisted (links: http, https, mailto, tel and relative; images: http, https, relative and data:image), a rejected link renders as its label, CSV cells are guarded against formula injection, and Markdown, Discord and Slack text is escaped.

Can I use my own components?

Yes. Any component that returns document primitives can sit in the tree; render() resolves it first. A DOM element such as <div> throws with a message naming it, because a PDF has no idea what a div is.

Can I add a format we need?

Register a renderer with registerRenderer('thermal', { render(node) { … } }) and call render(doc, 'thermal'). It receives the same DocNode tree the built-in renderers get.

Does it run in a native app?

Not on the device. Render on your server and fetch the file, or hand it to the system share sheet; both of those lower to iOS and Android on the experimental native targets.

One report. Every format someone will ask for next week.

bun add @pyreon/document
Read the documents guide