Repository navigation
Extract Images
huzpsb edited this page Oct 25, 2026
·
1 revision
Export all images embedded in a PDF — re-encoded to PNG where useful, with stable filenames.
pdfcpu2 extract -m image in.pdf outDir
pdfcpu2 extract -m image -p 1-3 in.pdf outDir # selected pages only
cat in.pdf | pdfcpu2 extract -m image - outDirFilenames follow <inBase>_<page>_<id>.<ext>, e.g. gallery_1_Im0.png. Soft masks and image masks are handled.
package main
import (
"context"
"github.com/huzpsb/pdfcpu2/pkg/api"
"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)
func main() {
ctx := context.Background()
conf := model.NewDefaultConfiguration()
err := api.ExtractImagesFile(ctx, "in.pdf", "./images", nil, conf)
if err != nil {
panic(err)
}
}Custom sink — decide yourself what happens to each image:
err := api.ExtractImages(ctx, f, nil, func(img model.Image, singleImgPerPage bool, pageNr int) error {
fmt.Printf("page %d: %dx%d %v\n", pageNr, img.Width, img.Height, img.Extension)
return nil // or write, upload, re-encode...
}, conf)Raw inventory without decoding: api.ExtractImagesRaw. See also Images (list + update).
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers