Repository navigation
Extract Content
huzpsb edited this page Oct 25, 2026
·
1 revision
Export the raw page content streams of a PDF — the drawing operators (Tj, cm, Do, …) behind every page. The substrate for content-level analysis, custom text mining and debugging.
pdfcpu2 extract -m content in.pdf outDir
pdfcpu2 extract -m content -p 2 in.pdf outDir
cat in.pdf | pdfcpu2 extract -m content - outDirWrites outDir/<inBase>_content_<page>.txt.
package main
import (
"context"
"io"
"os"
"github.com/huzpsb/pdfcpu2/pkg/api"
"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)
func main() {
ctx := context.Background()
conf := model.NewDefaultConfiguration()
f, _ := os.Open("in.pdf")
defer f.Close()
err := api.ExtractContent(ctx, f, nil, func(r io.Reader, pageNr int) error {
b, _ := io.ReadAll(r)
fmt.Printf("--- page %d ---\n%s\n", pageNr, b)
return nil
}, conf)
if err != nil {
panic(err)
}
// Or to disk
_ = api.ExtractContentFile(ctx, "in.pdf", "./content", nil, conf)
}For plain text (not operators) use Text Extraction; for page-level PDFs use Extract Pages.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers