Pagecraft
Pagecraft turns HTML and a practical subset of CSS into paginated PDF documents. It is built for things like invoices, reports, forms, catalogs, and shipping labels: documents where page size, pagination, and readable output matter.
The rendering engine is written in Go and is inspired by WeasyPrint. Pagecraft offers two ways to use the same renderer: a command-line program for any language that can start a process, and a Go package for applications written in Go. The CLI is a small wrapper around the library, so both produce PDFs through the same engine.
Install
Install the command with Go:
go install github.com/robtrivi/pagecraft/cmd/pagecraft@latest
This places the pagecraft executable in your Go binary directory. You can also build it from a checkout:
go build -o pagecraft ./cmd/pagecraft
Use the command
Render an HTML file and choose where to write the PDF:
pagecraft -o report.pdf report.html
With no input file, Pagecraft reads HTML from standard input and writes the PDF to standard output. This makes it easy to connect to other tools:
cat report.html | pagecraft > report.pdf
The output file is optional. Use -o - to write to standard output explicitly. Errors go to standard error and return a non-zero exit code.
Usage: pagecraft [options] [input.html]
Options:
-o path write PDF to this file (default: stdout; use - for stdout)
When the input is a file, relative stylesheets, images, and fonts are resolved from that file's directory. An explicit HTML <base> element takes precedence. For HTML from stdin, relative resources are resolved from the process working directory.
Call it from another language
For example, a Python application can invoke Pagecraft and pass HTML through stdin:
import subprocess
html = b"<h1>Monthly report</h1><p>Generated by Pagecraft.</p>"
with open("report.pdf", "wb") as pdf:
subprocess.run(["pagecraft"], input=html, stdout=pdf, check=True)
The same process interface works from JavaScript, Ruby, PHP, Rust, shell scripts, and other languages. Applications that need a persistent service or a language-specific binding can build those around the executable or the Go package.
Use from Go
Add Pagecraft to a Go project:
go get github.com/robtrivi/pagecraft
The Go API returns the PDF as a byte slice:
package main
import (
"os"
"github.com/robtrivi/pagecraft/render"
)
func main() {
pdf, err := render.RenderHTMLToPDF(`<style>@page { size: A4; margin: 20mm; }</style>
<h1>Monthly report</h1><p>Generated by Pagecraft.</p>`)
if err != nil {
panic(err)
}
if err := os.WriteFile("report.pdf", pdf, 0o644); err != nil {
panic(err)
}
}
Supported layout
Pagecraft supports HTML stylesheets and inline styles, physical page sizes and margins through @page, page footers with page counters, text wrapping, lists, tables, floats, flexbox, grid, and multi-page layout. It can render borders, backgrounds, common typography, PNG and JPEG images, SVG graphics, links, metadata, and TrueType fonts declared with @font-face.
Pagecraft implements a document-focused CSS subset, not a browser. Unsupported CSS may be ignored or render differently from Chromium. The examples/ directory has complete HTML documents for an invoice, an operations report, a product catalog, a shipping label, and a regional expansion plan with landscape appendices.
Example previews
Each preview shows the first page rendered by Pagecraft. Select a preview to open its HTML source.

Invoice
Operations report
Product catalog
Shipping label
Regional expansion plan
Development
Run the test suite and static checks:
go test ./...
go vet ./...
License
GNU GPL version 3 or later (GPL-3.0-or-later). See LICENSE.