2026-11-27 16:19 UTC

Go PDF fork adds offline OCR and text extraction in a single binary

state: expiredheat: lowuncertainty: mediumrelevance: mediumlocal-ocr document-ingestionhuzpsb

What is this?

pdfcpu2 is an independently maintained, Apache-2.0 hard fork of the Go PDF library pdfcpu. Its GitHub project says it adds offline OCR and PDF text extraction to the existing CLI and Go API, embedding a small PP-OCRv6 model in a single binary and requiring no Python, cgo, or external service. The maintainer also reports PDFBox-compatible extraction, Chinese and English OCR support, and benchmark results sourced from PaddlePaddle; these are project claims, not independently verified here. The fork is not guaranteed to track upstream, and page rendering is listed as planned rather than available.

Why it matters

A practical addition for Go developers and privacy-sensitive document pipelines: pdfcpu2 combines PDF text extraction and offline OCR in a command-line tool and Go API, potentially simplifying local ingestion for search or agent workflows. Its small embedded OCR model and no-Python/no-cgo approach are notable, but this is an individual-maintained fork, not evidence of a broader shift or a substitute proven superior to established OCR tools. Performance, accuracy across languages and document types, and maintenance over time remain open questions.

Current assessment

The project README describes pdfcpu2 as an independently maintained Apache-2.0 hard fork of pdfcpu, adding PDF text extraction and OCR while retaining existing PDF commands. It says the binary embeds a roughly 6 MB PP-OCRv6 tiny model, runs OCR offline using pure Go inference, and supports Windows, Linux, and macOS on amd64 and arm64. The CLI and Go API can add an invisible searchable text layer to scanned PDFs and extract text; the maintainer also reports Chinese/English OCR support and differential testing of extraction against PDFBox on more than 1,200 Chinese PDFs. These are project claims, not independently verified results. The README's OCR comparisons cite PaddlePaddle benchmarks, not a demonstrated head-to-head evaluation of this implementation on representative PDFs. The fork is not guaranteed to track upstream; page rendering is listed as planned. Useful to monitor for developers needing an easily deployed local ingestion component, especially where documents should not leave the machine; adoption, accuracy, throughput, and ongoing compatibility are not established by the supplied evidence.

Measured heat

no measured readings yet — the hourly heat pass fills this in

How the heat travelled

10-25 19:32 (minted)⭐ origin echo-reconstructedThe repository is the original artifact linked by the HN post. Its README says: “pdfcpu2 is a fork of pdfcpu that adds offline OCR and text
huzpsb on github (echo) · attributed from hn.story.50234607 · published time unknown
—
10-25 18:35first on hacker news · published · lag ?I added offline OCR and text extraction to pdfcpu
huzpsb
—
10-25 18:35amplified on hacker news 👑hn.story.50234607
huzpsb
peak 2 · 0 comments · 98% of case engagement
10-25 19:28our radar first saw it · lag ?discovery anchor: hn.story.50234607—

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnI added offline OCR and text extraction to pdfcpu
Retrieved article excerpt

Open article · Retrieved 2026-10-25T19:29:59.849193+00:00

# pdfcpu2

[中文版](https://github.com/huzpsb/pdfcpu2/blob/main/README_CN.md)

pdfcpu2 is a fork of pdfcpu that adds offline OCR and text extraction while retaining the existing PDF processing commands. It builds as a single static binary, with no Python, cgo, or external services required.

```
pdfcpu2 ocr scan.pdf scan_ocr.pdf && pdfcpu2 extract -m text scan_ocr.pdf -
```

This adds a searchable text layer to a scanned PDF and extracts the resulting text. The same pipeline can be used for RAG ingestion, agent tools, and batch document processing.

| `pdfcpu2 extract -m text`: extract text from a PDF | `pdfcpu2 ocr`: add an invisible, selectable text layer to scans |
| --- | --- |
| [Text extraction demo](https://github.com/huzpsb/pdfcpu2/blob/main/media/extract.png) | [OCR text layer](https://github.com/huzpsb/pdfcpu2/blob/main/media/ocr.png) |

## Documentation

The [project wiki](https://github.com/huzpsb/pdfcpu2/wiki) contains about 60 pages of documentation, including CLI usage, Go API examples, and getting-started guides.

## Motivation

Horst Rutter, the maintainer of pdfcpu, is a member of the PDF Association. I admire his commitment to the PDF standard. But I genuinely need text extraction, OCR, and related features in my own work. Respect for his work does not remove that need, so I added them here and use them.

## Features

- **Single binary.** The PP-OCRv6 detection and recognition models (about 6 MB) are embedded in the executable. OCR runs offline without API keys, tokens, rate limits, or data leaving the local machine. Windows, Linux, and macOS are supported on amd64 and arm64.
- **Pure Go OCR inference.** The models run on a pure Go engine using fp32 scalar math and goroutine-based parallelism. No cgo, ONNX Runtime, or Python is required.
- **OCR benchmarks.** PaddlePaddle's published benchmark reports the following results for PP-OCRv6 and several general-purpose VLMs:

  [PP-OCRv6 vs general-purpose VLMs](https://github.com/huzpsb/pdfcpu2/blob/main/media/pp.png)

  | Model | Text detection | Text recognition |
  | --- | --- | --- |
  | PP-OCRv6\_medium | **86.2** | **83.2** |
  | PP-OCRv6\_small | 84.1 | 81.3 |
  | **PP-OCRv6\_tiny** (embedded) | 80.6 | 73.5 |
  | Gemini-3.1-Pro | 46.8 | 71.4 |
  | GPT-5.5 | 45.6 | 64.2 |
  | Qwen3-VL-235B | 38.3 | 74.9 |

  Source: [PP-OCRv6 model card](https://www.modelscope.cn/models/PaddlePaddle/PP-OCRv6_small_rec_onnx). The specialized models also have no per-page API cost.
- **PDFBox-compatible text extraction.** `extract -m text` follows Apache PDFBox's default extractor. Behavior has been tuned through differential testing against PDFBox on a corpus of more than 1,200 real-world Chinese PDFs from different periods and generators.
- **CJK support.** Text extraction handles ToUnicode CMaps (including Type42 and array-form `bfrange`), embedded TrueType cmaps, legacy GBK/Big5, Adobe-GB1/CNS1 CID fallbacks, and a Latin-1 last resort. The OCR models are trained for Chinese and English.
- **Repeatable OCR.** Processed images are marked, so running `ocr` again only processes new content. Text is added as an invisible layer mapped through each image's page transform, keeping selection aligned with the visible glyphs.
- **CLI and API integration.** Supports stdin/stdout streaming (`-`), page selection, JSON output, and `context.Context` cancellation in the Go API.

## Additional commands

| Feature | Command | Status |
| --- | --- | --- |
| Plain-text extraction (PDFBox-compatible) | `pdfcpu2 extract -m text` | Available |
| Invisible OCR text layer for scanned PDFs | `pdfcpu2 ocr` | Available |
| Page rendering / rasterization | `pdfcpu2 render` | Planned |

```
# Text extraction
pdfcpu2 extract -m text in.pdf out.txt          # whole document
pdfcpu2 extract -m text -p 1-3 in.pdf -         # pages 1-3 to stdout

# OCR: make scans searchable and extractable
pdfcpu2 ocr scan.pdf scan_ocr.pdf               # all pages
pdfcpu2 ocr scan.pdf scan_ocr.pdf -pages 1-10   # selected pages
```

As Go code:

```
conf := model.NewDefaultConfiguration()
ctx := context.Background()

n, err := api.OCRFile(ctx, "scan.pdf", "scan_ocr.pdf", nil, conf) // images processed
err = api.ExtractTextFile(ctx, "scan_ocr.pdf", "out.txt", nil, nil, conf)

// Or extract structured text with line coordinates:
texts, err := api.ExtractText(ctx, rs, []string{"1-3"}, nil, conf) // []pdfcpu.PageText
```

## Existing PDF commands

The existing command set remains available, including validation, optimization, merge/split/trim, pages and boxes, stamps and watermarks, forms, encryption, permissions, signatures, attachments, PDF creation, n-up, booklets, and posters.

```
pdfcpu2 validate in.pdf
pdfcpu2 merge out.pdf a.pdf b.pdf
pdfcpu2 encrypt --opw owner --upw user in.pdf out.pdf   # AES-256
pdfcpu2 stamp add "CONFIDENTIAL" "pos:tr, op:.6" in.pdf out.pdf
```

## Installation

```
go install github.com/huzpsb/pdfcpu2/cmd/pdfcpu2@latest
# Or from a checkout:
go mod vendor && go build ./cmd/pdfcpu2
```

As a library:

```
go get github.com/huzpsb/pdfcpu2
```

## Relationship with upstream

pdfcpu2 is an independently maintained hard fork of pdfcpu, licensed under Apache 2.0. It is not guaranteed to track upstream releases. Issues and reasonable feature requests are welcome.

Existing behavior and API conventions remain compatible where practical. New code follows the existing package layering: `model` → `pkg/pdfcpu` → `pkg/api` → `pkg/cli`.

Upstream project: [pdfcpu](https://github.com/pdfcpu/pdfcpu).

## License

Apache License 2.0, same as upstream (see `LICENSE.txt`). The embedded Adobe CID-to-Unicode tables are derived from Adobe's UCS2 CMap resources (Adobe BSD-style license; copyright notice retained in the generated file's header).
huzpsb20
🟧 echo.github ⭐The repository is the original artifact linked by the HN post. Its README says: “pdfcpu2 is a fork of pdfcpu that adds offline OCR and text huzpsb——

Interpretation history

Decision trace