Repository navigation
Trim
huzpsb edited this page Oct 25, 2026
·
1 revision
Generate a trimmed version of a PDF containing only the selected pages. (For building custom page sequences — reorder, repeat — see Collect.)
pdfcpu2 trim -p pageSelection inFile [outFile]
-p is required. Omit outFile to overwrite inFile (needs --force if it exists).
pdfcpu2 trim -p 1-12 in.pdf out.pdf
pdfcpu2 trim -p 1,3-5,l in.pdf out.pdf
cat filing.pdf | pdfcpu2 trim -p 1-12 - - > filing-trimmed.pdfpackage 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.TrimFile(ctx, "in.pdf", "out.pdf", []string{"1-12"}, conf)
if err != nil {
panic(err)
}
}Reader/writer variant: api.Trim(ctx, rs, w, selectedPages, conf) streams the result to any io.Writer.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers