Skip to content
Installation and first applications

Installation and first applications

UniPDF is a pure Go module. There is no installer, no C library to link against and no system package: you add it to your project the way you add any other dependency.

go get github.com/unidoc/unipdf/v5

That records the newest v5 release in your go.mod. Tagged releases are listed on GitHub, and the module requires Go 1.25+ or newer.

Your first document

A license key has to be loaded before anything else touches the library, which is why it goes in init. This program writes a one-page PDF containing a line of text.

package main

import (
    "os"

    "github.com/unidoc/unipdf/v5/common/license"
    "github.com/unidoc/unipdf/v5/creator"
)

func init() {
    if err := license.SetMeteredKey(os.Getenv("UNIDOC_LICENSE_API_KEY")); err != nil {
        panic(err)
    }
}

func main() {
    c := creator.New()

    p := c.NewStyledParagraph()
    p.SetText("Hello World")

    if err := c.Draw(p); err != nil {
        panic(err)
    }

    if err := c.WriteToFile("hello.pdf"); err != nil {
        panic(err)
    }
}

creator.New starts an empty Letter-size document. Draw adds the first page for you and places the paragraph in the normal top-to-bottom flow, so a second call would land below the first without any positioning. Nothing is written until WriteToFile.

The creator package builds new content. Reading or changing a file that already exists starts from model.PdfReader instead, and the two combine: read the pages, pass them to Creator.AddPage, draw on top.

For an offline key, use license.SetLicenseKey with the key text and the customer name embedded in it. Both routes are covered in loading the license key.

Where to go next

Most projects start from an example that is close to what they need rather than from a blank file. The examples repository is organized by task, and report/pdf_report.go is the usual next step after the snippet above: chapters, a generated table of contents, headers and footers, and tables.

git clone https://github.com/unidoc/unipdf-examples.git
cd unipdf-examples/report
go run pdf_report.go

If this is your first time using UniPDF, follow the getting started guide to create an API key and set up your development environment.

The Playground runs UniPDF code in the browser with no local setup, and produces a shareable link. Support requests are much easier to answer when they come with one.

For a walkthrough that covers creating a UniCloud account and generating an API key, see getting started.

Last updated on