Recursive AI
onepdfGoAvailable

onepdf for Go

A free, open-source PDF library in pure Go, MIT or Apache-2.0. It reads, repairs and decrypts PDFs, extracts their text, edits, signs and redacts them, converts them to PDF/A and PDF/UA, and lays out new ones.

No third-party dependencies: it needs only our onefont module, which uses only the Go standard library.

go get recursiveai.org/go/onepdf

Fixed in v1.0.1

A quick look

The README’s text extraction example as a complete program. letter.pdf is the two-page letter that getting started lays out with the layout package.

Getting started
main.goGo
package main
 
import (
    "fmt"
    "log"
 
    "recursiveai.org/go/onepdf"
    "recursiveai.org/go/onepdf/text"
)
 
func main() {
    doc, err := onepdf.OpenFile("letter.pdf")
    if err != nil {
        log.Fatal(err)
    }
    // Reading order; text.Extract gives words, lines and blocks.
    s, err := text.Plain(doc)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(s)
}
OutputGo 1.26.8
Letter
 
Account 1234 is secret.
 
Terms
 
Payment is due in 30 days.

Install

Go 1.24 or newer. The substitute fonts, for laying out text without a font file of your own and for drawing fonts a PDF does not embed, are a separate module.

Substitute fonts
go get recursiveai.org/go/onepdf
go get recursiveai.org/go/onepdf/fonts@v1.0.1

Packages

Layout speed

The README’s layout benchmark: an invoice, a 50-page report, a 10,000-row table, a 500-page book and 32 invoices at once, laid out by onepdf and three other Go PDF libraries with the same font. onepdf writes tagged PDF; the others write untagged files. Medians of six runs on one machine with Go 1.26.8.

The layout rows and the method

Every layout row is ahead of the fastest competitor with tagging on.

README.md at v1.0.1

What it does