PDFs
Swift Rust includes a declarative PDF component tree. You write <Document>, <Page>, <Text>, and <View> like TSX, and the framework compiles them into a PDF binary.
A simple invoice
app/api/invoice/[id]/route.ts
import { Document, Page, Text, View } from "swift-rust/pdf";
export async function GET() {
return Response.pdf(
<Document title="Invoice #1001" author="Acme Co.">
<Page size="A4" margin={50}>
<View>
<Text fontSize={24} fontFamily="Helvetica-Bold">Invoice #1001</Text>
<Text fontSize={12}>Billed to: Acme Customer</Text>
</View>
<View x={0} y={400}>
<Text fontSize={10}>Thanks for your business.</Text>
</View>
</Page>
</Document>
);
}Page sizes
Page sizes: "A4", "A3", "Letter", "Legal", "Tabloid". Orientations: "portrait" (default) or "landscape".
Configuration
swift-rust.config.json
{
"pdf": {
"defaultPageSize": "A4",
"defaultOrientation": "portrait",
"compress": true
}
}Next steps
Continue to Deploying.