Repository navigation
Home
pdfcpu2 is a modernized fork of pdfcpu — a PDF processing library and command-line tool written in pure Go. It adds a set of quality-of-life features designed for AI-era workflows, most notably offline OCR and PDFBox-grade text extraction, on top of the complete upstream command set.
One static binary. No Python, no cgo, no external services, no API keys. Works offline on Windows, Linux and macOS.
| Single-file pipeline |
ocr + extract -m text turn a stack of scans into clean plain text with one executable. |
| Go native | The embedded PP-OCRv6 detection/recognition models run on a pure Go inference engine — fp32 scalar math, goroutine-parallel, no cgo, no ONNX runtime. |
| Offline first | Models are embedded in the binary (ppocr.bin, ~6 MB). -o disables all HTTP traffic. Nothing leaves your machine. |
| PDFBox-grade extraction | Text extraction output is aligned with Apache PDFBox's default extractor, tuned via differential testing over a corpus of 1200+ real-world Chinese PDFs spanning different eras. |
| Rendering built in |
render rasterizes pages to PNG/JPEG with a self-contained pure-Go engine; solidify rebuilds pages as image-only pages to stop copying and editing. |
| Anti-scraping |
obfuscate garbage fills the cmap/ToUnicode mappings of embedded CID fonts — rendering stays pixel-identical, extraction yields garbage. |
| CJK friendly | ToUnicode CMaps, legacy GBK/Big5 encodings, Adobe-GB1/CNS1 CID fallbacks, embedded TrueType cmaps — plus PP-OCR models trained on Chinese + English. |
| AI-workflow ready | Streams in (-) and out (-), page selection, JSON output, context-based Go API with cancellation — built for pipelines, RAG ingestion and agent tooling. |
# Build (or grab a release)
go mod vendor
go build ./cmd/pdfcpu2
# Make a scanned PDF searchable, then dump its text
pdfcpu2 ocr scan.pdf scan_ocr.pdf
pdfcpu2 extract -m text scan_ocr.pdf out.txtThe same pipeline as Go code:
package main
import (
"context"
"github.com/huzpsb/pdfcpu2/pkg/api"
"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)
func main() {
conf := model.NewDefaultConfiguration()
ctx := context.Background()
if _, err := api.OCRFile(ctx, "scan.pdf", "scan_ocr.pdf", nil, conf); err != nil {
panic(err)
}
if err := api.ExtractTextFile(ctx, "scan_ocr.pdf", "out.txt", nil, nil, conf); err != nil {
panic(err)
}
}pdfcpu2 ships the PP-OCRv6 tiny detection + recognition models. On PaddlePaddle's published benchmark (see model card), dedicated PP-OCR models outscore every tested general-purpose VLM:
| Model | Text detection | Text recognition |
|---|---|---|
| PP-OCRv6_medium | 86.2 | 83.2 |
| PP-OCRv6_small | 84.1 | 81.3 |
| PP-OCRv5_server | 81.6 | 78.1 |
| PP-OCRv6_tiny (embedded) | 80.6 | 73.5 |
| PP-OCRv5_mobile | 75.2 | 73.7 |
| Gemini-3.1-Pro | 46.8 | 71.4 |
| GPT-5.5 | 45.6 | 64.2 |
| Qwen3-VL-235B | 38.3 | 74.9 |
| Kimi-K2.6 | 12.8 | 62.9 |
| MiniMax-M3 | 12.0 | 54.1 |
See OCR for details.
| Feature | Command | Status |
|---|---|---|
| Plain-text extraction (PDFBox-compatible) | extract -m text |
Available — Text Extraction |
| Invisible OCR text layer for scans | ocr |
Available — OCR |
| Page rendering / rasterization | render |
Available — Render |
| Content freezing (image-only pages) | solidify |
Available — Solidify |
| Glyph obfuscation (anti text extraction) | obfuscate |
Available — Obfuscate |
| Local web app (WebAssembly, files never leave the device) | https://huzpsb.github.io/pdfcpu2/ | Available — Web UI |
Everything else — validation, optimization, encryption, page assembly, stamps, forms, signatures, … — is inherited from upstream pdfcpu and fully documented in this wiki, command by command, with both CLI usage and Go code. See the sidebar.
- Getting started: Installation · Quick Tour · Configuration · Page Selection · Passwords and Global Flags
- Fork features: Text Extraction · OCR · Render · Solidify · Obfuscate · Web UI · Roadmap
- Inspect: Validate · Info · Paper
- Document: Merge · Split · Trim · Collect · Optimize · Create · Import Images
- Pages: Pages · Rotate · Resize · Crop · Boxes · N-Up · Grid · Booklet · Zoom · Cut · N-Down · Poster
- Content: Annotations · Bookmarks · Keywords · Properties · Stamp · Watermark · Form · Images · Fonts
- Extract: Extract Images · Extract Fonts · Extract Content · Extract Pages · Extract Metadata
- Resources: Attachments · Portfolio
- Security: Encrypt · Decrypt · Change Password · Permissions
- Viewer: Page Layout · Page Mode · Viewer Preferences
- Trust: Certificates · Signatures
- Developers: Go API
pdfcpu2 is a hard fork of pdfcpu (Apache 2.0). It is maintained independently and does not track upstream releases on a guaranteed schedule. Upstream features, behavior and API conventions remain compatible; new code follows the upstream layering (model → pkg/pdfcpu → pkg/api → pkg/cli). For background on general PDF processing concepts, the upstream documentation is an excellent companion.
Apache License 2.0, same as upstream. This software embeds vivo Sans Light as the fallback font used for rendering text whose fonts are not embedded in a PDF (vivo Sans license: credited in-software, no modification or standalone redistribution; see pkg/render/internal/fallbackfont/vivoSans-LICENSE.txt). The embedded Adobe CID→Unicode tables are derived from Adobe's UCS2 CMap resources (Adobe BSD-style license).
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers