Repository navigation
Quick Tour
huzpsb edited this page Oct 25, 2026
·
1 revision
Ten minutes, ten commands — the fastest way to get a feel for pdfcpu2. Every command also has a Go API counterpart; see Go API.
pdfcpu2 validate in.pdfChecks spec compliance (PDF 1.7 / basic PDF 2.0). Use -m strict for pedantic mode, -l to check for broken links.
pdfcpu2 info in.pdf # human readable
pdfcpu2 info --json in.pdf # machine readable, great with jqThe fork's headline act — fully offline, one binary:
pdfcpu2 ocr scan.pdf scan_ocr.pdf # embed invisible text layer
pdfcpu2 extract -m text scan_ocr.pdf - # dump text to stdoutpdfcpu2 split in.pdf ./pages 1 # one PDF per page
pdfcpu2 merge out.pdf a.pdf b.pdf # concatenatepdfcpu2 trim -p 1-3,7 in.pdf out.pdf
pdfcpu2 collect -p 3,1,1 in.pdf out.pdf # custom sequence, repeats allowedpdfcpu2 stamp add "CONFIDENTIAL" "pos:tr, scale:.35 abs, op:.6" in.pdf out.pdfpdfcpu2 watermark add "DRAFT" "diag:1, scale:.8 rel, op:.25" in.pdf out.pdfpdfcpu2 nup out.pdf 4 in.pdfpdfcpu2 encrypt --opw owner --upw user in.pdf out.pdf # AES-256pdfcpu2 extract -m text in.pdf out.txt # whole document
pdfcpu2 extract -m text -p 1-3 in.pdf - # pages 1-3 to stdoutpackage main
import (
"context"
"github.com/huzpsb/pdfcpu2/pkg/api"
"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)
func main() {
ctx := context.Background()
conf := model.NewDefaultConfiguration()
_ = api.ValidateFile(ctx, "in.pdf", conf, nil)
_, _ = api.OCRFile(ctx, "scan.pdf", "scan_ocr.pdf", nil, conf)
_ = api.ExtractTextFile(ctx, "scan_ocr.pdf", "out.txt", nil, nil, conf)
_ = api.MergeCreateFile(ctx, []string{"a.pdf", "b.pdf"}, "out.pdf", false, conf)
_ = api.TrimFile(ctx, "in.pdf", "out.pdf", []string{"1-3", "7"}, conf)
}-
Page Selection — the
-pmini-language (odd,l,!2-4, …) -
Passwords and Global Flags —
-,--opw,-o,--force - Configuration — config dir, config.yml, stateless mode
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers