Repository navigation
Collect
huzpsb edited this page Oct 25, 2026
·
1 revision
Build a new PDF from a custom page sequence — reorder, repeat, mirror. Unlike Trim (which only filters), collect honors duplicates and order.
pdfcpu2 collect -p pageSelection inFile [outFile]
-p is required and may repeat pages:
pdfcpu2 collect -p 1,3,5-7 in.pdf out.pdf # exact sequence
pdfcpu2 collect -p l-1 in.pdf out.pdf # reversed document
pdfcpu2 collect -p 1,1,2 in.pdf out.pdf # repeats allowedpackage 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.CollectFile(ctx, "in.pdf", "out.pdf", []string{"1", "3", "5-7"}, conf)
if err != nil {
panic(err)
}
}Stream variant: api.Collect(ctx, rs, w, selectedPages, conf).
To resolve a selection into page numbers without writing anything:
pages, err := api.PagesForPageCollection(pageCount, []string{"l-1"})pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers