Free Go (Golang) gofpdf Templates & Visual Code Generator

Pure-Go FPDF-style writer with zero CGO — compiles into a tiny static binary and ranked #1 fastest overall in pure PDF generation (0.7 ms single-page; 15 ms, 0.03s CPU & 15.6 MB RAM across 22 stress-test pages). Upstream repo is archived (drop-in compatible with go-pdf/fpdf).

Install: go get github.com/jung-kurt/gofpdf@v1.20.0 | Runtime: Go (Go (Golang)) | Version: 1.20.0 | Popularity: 380k/mo installs

Works with: Go net/http, Gin, Fiber, Echo, Chi, AWS Lambda Go

How gofpdf (Go) Templates Work in CodePDF

Compiles visual designs into a pure Go program using gofpdf.NewCustom (PDF points, top-left origin) with typed Go structs, dynamic slice iteration, and vector shapes.

  • 100% pure Go with zero CGO — compiles into tiny static Linux/scratch Docker binaries
  • Eliminates manual pdf.SetXY() and CellFormat() coordinate trial-and-error
  • Typed Go data structs and slice loops ready for Gin, Echo, Fiber, or net/http handlers

Quick Start: Generate PDFs with gofpdf

Install gofpdf (Go) (Go (Golang)), then run the code CodePDF exports for any template:

go get github.com/jung-kurt/gofpdf@v1.20.0

  1. Run go get github.com/jung-kurt/gofpdf@v1.20.0 in your module.
  2. Save the generated file as main.go in your package.
  3. Run go run main.go to produce document.pdf.
  4. gofpdf uses a top-left origin in points, matching the CodePDF canvas directly.
  5. Images are loaded from a local path or URL — replace the placeholder paths before running.
  6. gofpdf is in maintenance mode; for an actively developed successor see github.com/go-pdf/fpdf.

Example gofpdf Output (Standard B2B Commercial Invoice)

Compiled directly from the Standard B2B Commercial Invoice template (Go (Golang)):

// This code is generated using codepdf.dev

package main

import (
	"fmt"
	"math"
	"strconv"
	"strings"

	"github.com/jung-kurt/gofpdf"
)

func toCp1252(s string) string {
    var out []byte
    for _, r := range s {
        if r < 0x80 || (r >= 0xA0 && r <= 0xFF) {
            out = append(out, byte(r))
            continue
        }
        switch r {
        case 0x20AC:
            out = append(out, 0x80)
        case 0x201A:
            out = append(out, 0x82)
        case 0x0192:
            out = append(out, 0x83)
        case 0x201E:
            out = append(out, 0x84)
        case 0x2026:
// … (870 more lines in full generated file)

Custom Fonts in gofpdf

Generated code defaults to Core 14 CP1252 fonts; register UTF-8 TrueType (.ttf) files via pdf.AddUTF8Font() and activate with pdf.SetFont() for custom typefaces.

  1. Place .ttf files in ./fonts/ relative to your Go working directory.
  2. Call pdf.AddUTF8Font("{{FONT_FAMILY}}", "", "{{FONT_LOCAL_PATH}}") before drawing text.
  3. Check pdf.Error() after font registration in case a TTF path is missing.

Official documentation: gofpdf docs

gofpdf Benchmark Results

Measured on CodePDF’s 26-component, 22-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).

gofpdf (Go) stress-test results and rank out of 22 PDF libraries
MetricgofpdfRank (of 22)
Wall-clock time15 ms1st fastest
CPU time0.03 s1st lowest
Peak RAM15.6 MB3rd lowest
PDF file size149.8 KB9th smallest
Engine type
Coordinate Canvas
Under the hood
Pure-Go port of FPDF (zero CGO, compiles into static single binary)
Runs in
Go (net/http, Gin, Echo, Fiber, AWS Lambda, scratch Docker)
Verdict
#1 fastest pure PDF generation overall (15 ms for 22p, 0.7 ms single-page, 15.6 MB RAM, 0.03s CPU); zero-CGO static Go binary.

Under the Hood & Benchmark Highlights

  • 100% pure Go with zero CGO — compiles into a tiny static binary that runs inside distroless or scratch Docker containers with no OS libraries.
  • Finished our 11-page 26-component stress test in 1.03s including go run compilation (0.61s CPU, 95.7 MB RAM, 124.0 KB PDF; 2.9 KB on single-page templates).
  • Upstream github.com/jung-kurt/gofpdf is archived, though the API works cleanly with the active MIT fork github.com/go-pdf/fpdf.

Good to Know (gofpdf Caveats)

  • Upstream repo is archived: github.com/jung-kurt/gofpdf is in maintenance/archived mode. The exported API is drop-in compatible with the actively maintained MIT community fork github.com/go-pdf/fpdf.
  • UTF-8 requires AddUTF8Font(): Built-in core fonts only cover Windows-1252/CP1252; load a .ttf font via pdf.AddUTF8Font() for full Unicode.
  • Coordinate-based API: Uses explicit SetXY/CellFormat positioning in top-left PDF points; check pdf.Error() after font or image calls because gofpdf accumulates errors silently.

Popular gofpdf PDF Templates

All 100 CodePDF templates export to gofpdf (Go). Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.

gofpdf Template FAQs

Does gofpdf require CGO or external C libraries in Docker?

No. gofpdf is pure Go and compiles into a single static binary that runs in distroless or scratch containers.

Can I stream generated gofpdf documents directly to an http.ResponseWriter?

Yes — replace pdf.OutputFileAndClose("output.pdf") with pdf.Output(w) inside any Go HTTP handler.

Are Go structs generated for dynamic template variables?

Yes — CodePDF inspects your template's data model and emits typed Go fields and sample initialization data.

Compare gofpdf with Other PDF Libraries

gofpdf is the only Go engine CodePDF targets. See the full 22-library benchmark rankings · Compare all supported PDF libraries