Quick start
Install @inkoxide/react and render a receipt from a React component.
Print-quality PDFs from React components.
@inkoxide/react turns React components into PDF documents. You write Document, Page,
View and Text, style them with Tailwind classes or style objects, and a layout engine
written in Rust does the typesetting: text shaping, line breaking, pagination and PDF output.
npm install @inkoxide/react
To style with Tailwind classes (className), as the example does, add:
npm install @inkoxide/tailwind
Save this as receipt.tsx:
/** @jsxRuntime automatic */
import { Document, Page, renderToFile, Text, View } from '@inkoxide/react';
interface Line {
name: string;
amount: number;
}
export default function Receipt({ customer, lines }: { customer: string; lines: Line[] }) {
const total = lines.reduce((sum, l) => sum + l.amount, 0);
return (
<Document title={`Receipt for ${customer}`}>
<Page size="A6" className="p-8 text-xs text-gray-900">
<Text className="text-lg font-bold">Receipt</Text>
<Text className="mb-4 text-gray-500">for {customer}</Text>
{lines.map((l) => (
<View key={l.name} className="flex-row justify-between border-b border-gray-200 py-1.5">
<Text>{l.name}</Text>
<Text>${l.amount.toFixed(2)}</Text>
</View>
))}
<View className="mt-3 flex-row justify-between font-bold">
<Text>Total</Text>
<Text>${total.toFixed(2)}</Text>
</View>
</Page>
</Document>
);
}
export const sample = {
customer: 'Ada Lovelace',
lines: [
{ name: 'Espresso', amount: 3.2 },
{ name: 'Almond croissant', amount: 4.5 },
{ name: 'Sparkling water', amount: 2 },
],
};
renderToFile(<Receipt {...sample} />, 'receipt.pdf');
Run it with npx tsx receipt.tsx, which writes receipt.pdf:

Switch to Layout for the boxes the engine laid out.
Drawn by the engine’s debug option, sizes in points.
In a server, renderToBuffer(<Receipt … />) returns the bytes to send, and
renderToStream(<Receipt … />) a stream to pipe into the response.
Synced from packages/react/README.md in the inkoxide repository.
