Leadtype draws inspiration from traditional typesetting while providing a modern Go toolkit for LTML and PDF generation.
Leadtype is a Go toolkit for generating PDF documents, working with AFM and TrueType fonts, composing rich text, and rendering LTML documents into finished pages.
It is organized as a library-first project with small command-line tools and runnable samples. If you want to build PDFs directly from Go, inspect and load fonts, or render XML-driven document layouts, this repository gives you the core pieces in one place.
- Generate PDFs from Go with a low-level writer and higher-level page helpers.
- Use built-in AFM fonts or load TrueType and TrueType Collection fonts.
- Render rich text with font styling, color, underline, and mixed formatting.
- Render LTML, an XML-based document and layout language built on the PDF stack.
- Use modern Unicode Type 0 / CIDFont output for TrueType fonts, including multi-script text and
ToUnicodemaps. - Explore working examples under
samples/and focused CLI tools undercmd/.
Leadtype is under active development and is approaching release quality. The codebase is already broadly usable, with solid package-level test coverage and a growing set of end-to-end samples.
Leadtype requires Go 1.21+.
Clone the repository:
git clone https://github.com/rowland/leadtype.git
cd leadtypeLTML is one of the most distinctive parts of the project: an XML-based document and layout language that renders through Leadtype's PDF engine.
Render one of the checked-in LTML samples:
go run ./cmd/render-ltml -o /tmp/hello-ltml.pdf ltml/samples/test_003_hello_world.ltml
go run ./cmd/render-ltml -o /tmp/rich-text.pdf ltml/samples/test_010_rich_text.ltml
go run ./cmd/render-ltml -o /tmp/cjk-thai-grid.pdf ltml/samples/test_012_cjk_thai_grid.ltml
go run ./cmd/render-ltml -o /tmp/arabic-program.pdf ltml/samples/test_033_arabic_program.ltmlThere are 33 LTML sample documents under ltml/samples/, covering basic pages, flow and box layout, tables, rich text, images, transforms, overflow behavior, encodings, Arabic text, and more.
To regenerate the sample PDFs beside their .ltml files:
make ltml-samplesThat target renders Arabic-capable samples with the built-in pure-Go shaper so
joined right-to-left glyph shaping is exercised by default. The local
bin/render-ltml and bin/serve-ltml binaries built by make binaries use
the same default behavior.
Leadtype also includes Go-based samples that exercise the lower-level PDF and font APIs directly:
go run ./samples -list
go run ./samples test_003_hello_world
go run ./samples test_009_unicode_ttf
go run ./samples test_022_emojiRun the standard project checks:
go build ./...
go test ./...Some samples depend on fonts available on the local machine, especially when using ttf_fonts.NewFromSystemFonts().
This example creates a simple PDF using a built-in AFM font and writes it to disk:
package main
import (
"os"
"github.com/rowland/leadtype/afm_fonts"
"github.com/rowland/leadtype/options"
"github.com/rowland/leadtype/pdf"
)
func main() {
out, err := os.Create("hello.pdf")
if err != nil {
panic(err)
}
defer out.Close()
doc := pdf.NewDocWriter()
afm, err := afm_fonts.Default()
if err != nil {
panic(err)
}
doc.AddFontSource(afm)
doc.NewPage()
doc.SetUnits("in")
if _, err := doc.SetFont("Helvetica", 12, options.Options{}); err != nil {
panic(err)
}
doc.MoveTo(1, 1)
doc.Print("Hello, Leadtype!")
if _, err := doc.WriteTo(out); err != nil {
panic(err)
}
}For more involved examples, see samples/test_003_hello_world.go, samples/test_006_rich_text.go, and samples/test_009_unicode_ttf.go.
If you want to start from LTML instead of Go code, browse ltml/samples/ and render them with cmd/render-ltml. The sample set includes selector and pseudo-class examples such as ltml/samples/test_041_pseudo_classes.ltml.
The pdf package also includes gradient fills, stroke gradients, clipping-based shading paints, and related drawing APIs. See pdf/README.md for package-specific usage notes.
Leadtype includes a few focused utilities:
cmd/render-ltml: render an LTML document to PDF locally or submit it to a remote render service.cmd/serve-ltml: run an HTTP service that accepts LTML plus uploaded assets and returns PDFs.ttdump/: inspect TrueType font metadata.ttquery/: query installed TrueType fonts for capabilities such as Arabic shaping or emoji coverage.
You can run them from the repository:
go run ./cmd/render-ltml -h
go run ./cmd/serve-ltml -h
go run ./ttdump -h
go run ./ttquery capabilities
go run ./ttquery emojiOr install them:
go install github.com/rowland/leadtype/cmd/render-ltml@latest
go install github.com/rowland/leadtype/cmd/serve-ltml@latest
go install github.com/rowland/leadtype/ttdump@latest
go install github.com/rowland/leadtype/ttquery@latestpdf/: core PDF writer, document model, pages, text, images, and font embedding.font/: shared font abstraction used by AFM and TTF paths.ttf/: TrueType parsing, metrics, cmap handling, and subsetting support.ttf_fonts/: load fonts from the filesystem or standard system font directories.afm/andafm_fonts/: Adobe Font Metrics support and bundled AFM font data.rich_text/: rich-text composition helpers for mixed styles.ltml/: XML-based document, widget, and layout layer on top of the PDF engine.codepage/,colors/,options/,wordbreaking/: supporting utilities used across the stack.samples/: runnable examples that generate PDFs.docs/: development notes and Unicode rendering design documents.
samples/README.md: how to list and run the included examples.cmd/render-ltml/README.md: local and remote LTML rendering CLI usage.cmd/serve-ltml/README.md: HTTP rendering service API and configuration.docs/development-process.md: workflow, testing strategy, and fixture guidance.docs/curved-text.md: staged curved-text API roadmap for the PDF layer.docs/curved-text-ltml.md: LTML planning note for future curved-text syntax.docs/unicode-pdf-rendering.md: design overview for Unicode and composite-font PDF output.docs/unicode-pdf-rendering-todo.md: implementation checklist for the Unicode workstream.
For most changes, the expected baseline is:
go build ./...
go test ./...Small, reviewable changes are preferred, and package-level tests are the norm throughout the repository.
The README banner is adapted from Metal movable type by Willi Heidelbach via Wikimedia Commons, licensed under CC BY 2.5. The repository copy is cropped from the original. See docs/assets/ATTRIBUTION.md for details.
