Skip to content

Golang HTML to PDF

HTML to PDF Golang API and the Chromedp Alternative for Go Services

Turn an html/template result or a live URL into a searchable, pixel accurate PDF with one HTTP call from Go. Managed Chromium renders your real CSS, web fonts and JavaScript, so you keep chromedp, Rod and the archived wkhtmltopdf wrappers out of your container. Try it on any URL or HTML below.

  • PDF and archive in one call
  • Plans from $49 a month
  • Your HTML stays yours

Live demo

Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.

Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.

See the plan

Short answer

To convert HTML to PDF in Golang, execute your html/template into a string and hand it to a renderer. Go has no built in HTML layout engine, so the options are chromedp or Rod, which drive Chromium and require a browser inside your image, a wkhtmltopdf wrapper, which depends on a project archived in 2023, or a rendering API called with net/http. SitePDF renders in managed Chromium and returns a true vector PDF with selectable text, plus an optional dated archive of exactly what it produced.

Written and fact checked by the SitePDF team.

Five ways to make a PDF from Go, compared

Go has no standard library PDF renderer, and the language is usually chosen for small static binaries, which is exactly what a browser dependency undoes. These routes differ on engine, what you must install and run, and whether your existing CSS survives.

Approach Engine CSS and JavaScript What you run Best for
chromedp
Chromium over CDP
Chromium, driven from Go with Page.PrintToPDF Full modern CSS and JavaScript Chromium installed in your image, plus pool and crash handling Services where owning a browser is acceptable
Rod
Chromium over CDP
Chromium, higher level Go API Full modern CSS and JavaScript Chromium in your image, rod can download its own build Teams who prefer a Puppeteer style API in Go
go-wkhtmltopdf wrappers
legacy
wkhtmltopdf, an old WebKit fork Dated CSS, no flexbox or grid, unreliable JavaScript A wkhtmltopdf binary per platform Existing services with a migration planned
gofpdf, fpdf forks, Maroto
draw in code
No HTML engine, you place text and boxes in Go None, you do not use CSS Nothing external Labels, tickets and fixed structured documents
Managed Chromium API
SitePDF
Chromium, run and scaled by us Full modern CSS and JavaScript One HTTP call, no browser in your container Invoices, statements, reports and a dated record

The honest read: chromedp and Rod are excellent and give you the same Chromium output we do at no license cost, if you are willing to ship and scale a browser. The drawing libraries are the right tool when there is no HTML version of the document. An API earns its place when a browser does not belong in a scratch or distroless image, when volume is spiky, or when you need a retrievable, timestamped copy of what you generated.

The wkhtmltopdf wrappers are the first thing to retire

Search Go PDF questions and the oldest answers point at wrappers around wkhtmltopdf. The underlying project was archived in 2023, which means no further fixes of any kind, security included, and its engine is an old WebKit fork. A template with flexbox or grid will not lay out, web fonts are fragile and JavaScript rendered content is a coin flip. A wrapper also forces you to install a native binary in every image, which cancels the main reason people pick Go. If you run one today, pin the binary and plan the move. The same story, from the other side of the fence, is told on the wkhtmltopdf alternative page.

chromedp and Rod put a browser next to your binary

Both libraries talk to Chromium over the DevTools protocol and call Chromium's print to PDF, so the output matches Chrome's print preview. That is the fidelity you want. The bill arrives in operations. Chromium has to exist in the image, which means a base image with fonts and shared libraries instead of scratch. Each render holds a browser tab that can use hundreds of megabytes on a heavy page, a hung page needs a context timeout and a kill, and a month-end burst needs a worker pool you size for the peak rather than the average. None of that is hard, and plenty of teams run it happily. It is a standing cost, and it is the part an API removes. Gotenberg is the usual middle path: an open source Docker service that wraps Chromium behind an HTTP API, so the browser lives outside your Go binary. You still host, patch and scale that container yourself, which makes it the cheapest route when you want to own the infrastructure and a poor one when you do not. The cost side of the same decision for Node is worked through in the Puppeteer alternative page and, with real arithmetic, in the Playwright production cost article.

The API path from Go is about thirty lines

Render the template to a string exactly as you would for chromedp, then post it. There is nothing to import beyond the standard library.

var buf bytes.Buffer
if err := invoiceTmpl.Execute(&buf, invoice); err != nil {
    return err
}

body, _ := json.Marshal(map[string]any{
    "html":    buf.String(),
    "format":  "Letter",
    "archive": true,
})
req, _ := http.NewRequestWithContext(ctx, "POST",
    "https://api.sitepdf.com/v1/render", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("SITEPDF_KEY"))
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)
if err != nil {
    return err
}
defer resp.Body.Close()

var out struct {
    PDFURL string `json:"pdf_url"`
}
json.NewDecoder(resp.Body).Decode(&out)

Your CSS, fonts and any chart script render as they do in Chrome, the text stays selectable, and a traffic spike becomes an HTTP concurrency question instead of a memory incident in your pod. Put the call behind a worker or a queue for batch jobs and use the request context for timeouts. Every parameter is listed on the PDF generator API page, and bulk runs are covered on bulk HTML to PDF.

When to use a drawing library instead

If the document has no HTML version and never will, a shipping label, a ticket, a certificate with a fixed layout, then a code drawn PDF is simpler and faster than any renderer. The original gofpdf was archived, so look at the maintained forks or at Maroto, which builds on top of one. The price is that the layout lives in Go code and drifts from your web pages. Use a drawing library when there is no page to mirror, and a renderer when there is one.

Keep a dated copy of every document you generated

An invoice or statement that leaves your service leaves nothing verifiable behind. Send archive: true and SitePDF also stores a timestamped, immutable snapshot of exactly what it rendered, retrievable by id, so you can show what a customer saw on a given date. The website archiving page explains the record. Leave it off and we return the PDF and store nothing.

Rust is the other compiled option

Teams in Rust face the same Chromium decision. The Rust version of the cost breakdown covers the headless Chrome crates against an API call from reqwest.

Post your rendered template, or point the API at a live route. A real browser prints it.
curl https://api.sitepdf.com/v1/render \
  -H "Authorization: Bearer $SITEPDF_KEY" \
  -F url=https://app.example.com/invoices/8842 \
  -F format=Letter \
  -F print_background=true \
  -F archive=true

{
  "pdf_url": "https://api.sitepdf.com/v1/documents/doc_go41c.pdf",
  "pages": 2,
  "rendered_in_ms": 1480,
  "archive": {
    "id": "arc_go73e",
    "captured_at": "2026-11-15T09:12:44Z"
  }
}

This is the documented API call shape. Full request and response walkthrough.

Questions about this job

How do I convert HTML to PDF in Golang?
Execute your html/template into a string, then pass it to a renderer. chromedp and Rod drive Chromium from Go, so your CSS and JavaScript survive but you install and scale a browser. A rendering API takes the same HTML over one net/http call and returns a searchable PDF, with no browser in your container.
Is chromedp good for generating PDFs?
Yes, it calls Chromium print to PDF, so output matches Chrome. The cost is operational: Chromium must be in your image, each render needs a timeout, and bursts need a worker pool sized for peak load. Teams that want fidelity without owning a browser use an API instead.
Is there a pure Go HTML to PDF library?
Not with real CSS support. Pure Go libraries such as the fpdf forks and Maroto draw text and boxes in code rather than laying out HTML. For documents that mirror a web page, flexbox, grid and web fonts need a browser engine, which means chromedp, Rod or an API.
Should I still use a wkhtmltopdf wrapper in Go?
Not for new services. wkhtmltopdf was archived in 2023, receives no security fixes and cannot lay out modern CSS, and its Go wrappers need a native binary in every image. Existing services can pin the binary short term while they migrate to Chromium based rendering.
How much does a Go HTML to PDF API cost?
SitePDF API plans start at $49 a month for 10,000 renders, $99 for 50,000 and $299 for 250,000, with yearly billing saving about half on the smaller tiers. Compare that with the engineering hours and server memory a self-hosted browser pool takes.

Index

More PDF and archiving tools

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan