Repository navigation
Split
huzpsb edited this page Oct 25, 2026
·
1 revision
Split a PDF into a set of PDFs in an output directory — by fixed span, along bookmarks, or before specific page numbers.
pdfcpu2 split [-m span|bookmark|page] inFile outDir [ span | pageNr... ]
| Mode | Meaning | Extra arg |
|---|---|---|
span (default) |
fixed number of pages per output file | span (default 1) |
bookmark |
one output file per bookmark section | — |
page |
split before the given page numbers | page numbers |
pdfcpu2 split in.pdf . # one file per page: in_1.pdf, in_2.pdf, ...
pdfcpu2 split in.pdf . 2 # in_1-2.pdf, in_3-4.pdf, ...
pdfcpu2 split -m bookmark in.pdf . # in_bm1Title_1-4.pdf, ...
pdfcpu2 split -m page in.pdf . 2 4 10 # in_1.pdf, in_2-3.pdf, in_4-9.pdf, in_10-20.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()
// Span mode: 2 pages per output file
err := api.SplitFile(ctx, "in.pdf", "./out", 2, conf)
if err != nil {
panic(err)
}
// Page-number mode
err = api.SplitByPageNrFile(ctx, "in.pdf", "./out", []int{2, 4, 10}, conf)
_ = err
}api.SplitRaw(ctx, rs, span, conf) returns []*api.PageSpan (offsets, no files written) when you just need the layout.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers