Extraction · Go
Extract text from a PDF in Go
Pull the text out of any PDF from Go. rust-pdf walks the content stream, maps shown glyph codes back to Unicode through each font's ToUnicode map, and infers spaces and line breaks, including two-byte Type0 fonts and CJK.
Last updated: 2026-06-29
Why Go needs this
Search, indexing and RAG pipelines written in Go all begin by pulling the text out of a PDF, but the codes inside a content stream are font-specific bytes, not characters. Map them naively and you get mojibake: the wrong glyphs, no spaces, and broken word boundaries.
rust-pdf walks the content stream and maps every shown code back to Unicode through the font's ToUnicode CMap, including two-byte Type0 fonts, then infers spaces from large negative adjustments and line breaks from text positioning. Japanese, Greek and Arabic come back as the text a human reads.
ExtractText is a pure function over a byte slice with no shared state, which makes batch work trivial in Go: feed a directory through a worker pool or an errgroup and extract across goroutines, each call returning its own error so a single bad file never blocks the rest of the run.
- Maps glyph codes to Unicode via each font's ToUnicode map, including two-byte Type0 and CJK.
- Infers spaces from large negative adjustments and line breaks from text positioning.
- Pull raster images out too: JPEGs verbatim as .jpg, everything else as .png.
Extract text in Go with rust-pdf
Install with go get, then call the same idiomatic API every rust-pdf binding shares. The snippet below is real Go code from the reference docs.
go get github.com/rustpdf/rustpdf-go
data, _ := os.ReadFile("report.pdf")
text, _ := rustpdf.ExtractText(data)
fmt.Println(text)
n, _ := rustpdf.ExtractImagesToDir(data, "out_images/") // returns how many were written
fmt.Printf("wrote %d image(s)\n", n)
This is part of the free tier in Go. No license required.
Full Go reference in the documentation.
Text extraction in Go: FAQ
Does it extract Unicode and CJK text in Go?
Yes. Each shown code is mapped back to Unicode through the font's ToUnicode CMap, including two-byte Type0 fonts, so Japanese, Greek, Arabic and other scripts come back correctly.
Can it extract scanned PDFs?
No. Extraction reads the text layer of a PDF. A scanned document is an image with no text layer, which needs OCR first. For PDFs that contain real text, extraction is exact.
Is text extraction free?
Yes. Text and image extraction are part of the free tier in Go. No license token is required.
Can I extract many PDFs concurrently in Go?
Yes. ExtractText is a pure function over a byte slice with no shared state, so you can call it from a worker pool or an errgroup and process thousands of files across goroutines. Each call returns its own text and error, so one corrupt PDF fails in isolation instead of stalling the batch.
Turn PDFs into searchable text in Go
One Rust core, the same extracted Unicode in every language. Text and image extraction are free in Go, with nothing to license.