htmltopdf

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT

README

htmltopdf

A pure-Go engine that renders HTML and CSS to PDF, with no browser and no external binary. API reference: go doc github.com/glimps-re/htmltopdf/pkg/htmltopdf; supported CSS: docs/css-support.md.

Example

conv, err := htmltopdf.New(htmltopdf.Options{
	ExtraCSS: "@page { size: A4; margin: 20mm }",
})
if err != nil {
	log.Fatal(err)
}
var pdf bytes.Buffer
res, err := conv.Render(context.Background(),
	strings.NewReader("<h1>Report</h1><p>Hello, <b>world</b>.</p>"), &pdf)
if err != nil {
	log.Fatal(err)
}
fmt.Println(res.Pages, "page")

CI

.github/workflows/go.yml is the source of truth for triggers and versions. CI runs go test ./... without the race detector and needs no secret. The race suite (go test -race ./...) is a local gate: it takes minutes per package, so give it -timeout 30m.

Directories

Path Synopsis
internal
box
Package box builds the box tree of a document: the layout input.
Package box builds the box tree of a document: the layout input.
budget
Package budget enforces the per-render resource limits of the converter.
Package budget enforces the per-render resource limits of the converter.
css
Package css tokenizes and parses CSS into compact tokens and a rule tree.
Package css tokenizes and parses CSS into compact tokens and a rule tree.
display
Package display defines the display list: what layout hands to paint, one list per page.
Package display defines the display list: what layout hands to paint, one list per page.
dom
Package dom turns untrusted HTML into a compact, sanitized document tree.
Package dom turns untrusted HTML into a compact, sanitized document tree.
layout
Package layout lays the box tree out on pages.
Package layout lays the box tree out on pages.
paint
Package paint turns the display list of a page into PDF content operators.
Package paint turns the display list of a page into PDF content operators.
pdf
Package pdf is a minimal streaming PDF 1.7 writer.
Package pdf is a minimal streaming PDF 1.7 writer.
pdf/pdftest
Package pdftest is an independent reader and validator for the PDFs the writer produces.
Package pdftest is an independent reader and validator for the PDFs the writer produces.
style
Package style computes the CSS style of the elements of a document.
Package style computes the CSS style of the elements of a document.
svg
Package svg parses the subset of SVG that reduces to filled and stroked paths: path, rect, circle, ellipse, line, polyline, polygon and g.
Package svg parses the subset of SVG that reduces to filled and stroked paths: path, rect, circle, ellipse, line, polyline, polygon and g.
testcorpus
Package testcorpus generates the deterministic test fixtures of the converter: the report templates filled with fake data, hostile documents and the host-connector reference configuration.
Package testcorpus generates the deterministic test fixtures of the converter: the report templates filled with fake data, hostile documents and the host-connector reference configuration.
text
Package text selects fonts, shapes text and finds line-break opportunities.
Package text selects fonts, shapes text and finds line-break opportunities.
textsafe
Package textsafe classifies characters that must never reach a PDF string, a warning detail or a drawn text: controls, format characters (bidi, zero width, soft hyphen, tags) and line or paragraph separators.
Package textsafe classifies characters that must never reach a PDF string, a warning detail or a drawn text: controls, format characters (bidi, zero width, soft hyphen, tags) and line or paragraph separators.
pkg
htmltopdf
Package htmltopdf renders HTML documents styled with CSS to PDF without a browser.
Package htmltopdf renders HTML documents styled with CSS to PDF without a browser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL