Installation

Requirements

  • Go 1.22 or later
  • No external dependencies required

Install

go get github.com/gpdf-dev/gpdf

Module Setup

Add gpdf to your go.mod:

module your-project

go 1.22

require github.com/gpdf-dev/gpdf v1.0.3

gpdf has zero external dependencies — it only uses the Go standard library. No CGo, no system libraries, no complex build steps.

Verify Installation

package main

import (
    "fmt"
    "github.com/gpdf-dev/gpdf/document"
    "github.com/gpdf-dev/gpdf/template"
)

func main() {
    doc := template.New(template.WithPageSize(document.A4))
    page := doc.AddPage()
    page.AutoRow(func(r *template.RowBuilder) {
        r.Col(12, func(c *template.ColBuilder) {
            c.Text("gpdf is working!")
        })
    })
    data, err := doc.Generate()
    if err != nil {
        panic(err)
    }
    fmt.Printf("Generated PDF: %d bytes\n", len(data))
}
go run main.go
# Output: Generated PDF: 1234 bytes

Package Structure

gpdf is organized in three layers. Import only what you need:

import (
    "github.com/gpdf-dev/gpdf"            // Facade (re-exports)
    "github.com/gpdf-dev/gpdf/template"    // Layer 3: Builder API, Components
    "github.com/gpdf-dev/gpdf/document"    // Layer 2: Types, Styles, Units
    "github.com/gpdf-dev/gpdf/pdf"         // Layer 1: Colors, PDF primitives
)
PackageLayerPurpose
template3Builder API, JSON Schema, Go Templates, Components
document2Page sizes, Units (Mm, Pt, etc.), Styles, Node types
pdf1Colors (RGB, Hex, Gray), PDF Writer, Font embedding
qrcodeQR code generation
barcodeBarcode generation (Code 128)

Next Steps