Repository navigation
Page Selection
huzpsb edited this page Oct 25, 2026
·
1 revision
Many commands accept -p / --pages. pdfcpu2 understands a small expression language for selecting pages.
| Expression | Meaning |
|---|---|
3 |
page 3 |
1-3 |
pages 1 through 3 |
1- / -3
|
open ended ranges: from 1 / up to 3 |
l |
last page |
ll |
second to last page |
even / odd
|
all even / odd pages |
!2-4 |
negation: all pages except 2–4 |
1-3,7,l |
comma-separated union |
even,!2 |
combinations |
Print the full definition anytime:
pdfcpu2 selectedpagespdfcpu2 rotate in.pdf 90 -p odd # rotate odd pages
pdfcpu2 trim -p 1-3,7- in.pdf out.pdf # keep selection
pdfcpu2 extract -m text -p l-2 in.pdf - # careful: ranges are ascending; use 2-l
pdfcpu2 nup out.pdf 9 img.jpg --pages=3- # everything from page 3Page numbers are 1-based. Repeated pages in a selection are allowed only where a sequence is built (Collect); for processing commands duplicates are ignored.
Page selections are passed as []string, mirroring the CLI syntax:
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()
// Rotate odd pages by 90 degrees clockwise.
err := api.RotateFile(ctx, "in.pdf", "out.pdf", 90, []string{"odd"}, conf)
if err != nil {
panic(err)
}
}For fine-grained control, api.PagesForPageSelection(pageCount, selection, ensureAllForNone, false) resolves a selection into a page set you can inspect before running an operation.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers