Authoring · Go
Generate a PDF in Go
Create PDFs programmatically from Go: pages, vector graphics, embedded and subset fonts with full Unicode shaping, justified paragraphs, tables and images. rust-pdf gives Go a fast, memory-safe core with deterministic output.
Last updated: 2026-06-29
Why Go needs this
Most Go teams that need an invoice, report or shipping label find their options are an archived gofpdf or a commercial SDK. Neither pairs modern font shaping with a free, scriptable core, so simple documents end up harder to build than they should be.
Generation is rust-pdf's free foundation: draw vector shapes, place HarfBuzz-quality shaped and kerned Unicode text, lay out wrapping and justified paragraphs, build tables, and embed JPEG and PNG images, all from one idiomatic Go API with no per-document cost.
The same input always produces the same bytes, which is unusual for a PDF engine and exactly what Go testing wants: assert a generated document against a golden file, or serve it from a Gin handler and cache the response with confidence it will not drift between runs.
- Vector graphics, embedded and subset fonts, HarfBuzz-quality Unicode shaping and kerning.
- Wrapping and justified paragraphs, tables, images (JPEG, PNG, alpha, 16-bit).
- Deterministic output: identical bytes for identical input, ideal for audits and tests.
Generate a PDF in Go with rust-pdf
Install with go get, then call the same idiomatic API every rust-pdf binding shares. The snippet below is real Go code from the reference docs.
go get github.com/rustpdf/rustpdf-go
package main
import rustpdf "github.com/rustpdf/rustpdf-go"
func main() {
doc, _ := rustpdf.New() // A4 by default
defer doc.Close()
_ = doc.AddPage()
_ = doc.SetFillRGB(0.86, 0.20, 0.18)
_ = doc.Rect(72, 640, 200, 120) // x, y, width, height (points)
_ = doc.Fill()
_ = doc.Save("out.pdf")
}
Everything is free.
Full Go reference in the documentation.
Generation in Go: FAQ
Is generating PDFs free in Go?
Yes. All basic generation (pages, graphics, fonts, text, paragraphs, images, links, bookmarks, watermarks) is free forever, as are PDF/A, signatures and encryption.
Does it support Unicode and custom fonts?
Yes. Fonts are embedded and subset with HarfBuzz-quality shaping and kerning, using Type0 fonts with ToUnicode, so non-Latin scripts render and extract correctly.
Why a Rust core for Go?
One memory-safe, high-performance Rust core is exposed to Go through a thin idiomatic binding. You get the same engine, the same features and deterministic output, without a heavy runtime.
How do I stream a generated PDF to an HTTP response in Go?
Build the document, save it, and serve the result from a net/http or Gin handler with Content-Type application/pdf. Because identical input yields identical bytes, you can cache the response and assert it in a golden-file test without any flakiness.
Start building PDFs in Go today
One Rust core, the same output in every language — free and MIT licensed.