027: PDF invoice
A Piko project that renders an invoice as HTML from a PK template, converts it to PDF server-side, and returns the bytes to the browser for download.
What this demonstrates
- A PK template dedicated to PDF rendering at A4 print dimensions (fixed pixel content width, typed props).
- Server-side HTML-to-PDF conversion.
- A server action that renders the PDF server-side and returns it as a base64-encoded string (in a
GenerateResponse), which the page decodes and turns into a downloadable Blob. - Returning the rendered PDF base64-encoded to the client for immediate browser download (no server-side persistence).
Project structure
src/
cmd/
main/main.go Bootstrap; PDF service is auto-wired when pdfs/ is present.
generator/main.go Per-project generator entry point.
pages/
index.pk Form for triggering invoice generation.
actions/
invoice/
generate.go Builds the PDF and returns it base64-encoded to the client.
generate_secure.go Same flow with AES-256 encryption (password protection) and a CONFIDENTIAL watermark applied.
pdfs/
invoice.pk PDF template (A4 layout).
secure_invoice.pk Variant rendered with security transformers.
internal/dto/ Internal DTO shared between action and template.
How to run this example
From the Piko repository root:
cd examples/scenarios/027_pdf_invoice/src/
go mod tidy
air