Skip to content
huzpsb edited this page Oct 25, 2026 · 1 revision

Crop

Set the crop box for selected pages — the region visible on screen and in print. Content outside the crop box stays in the file (non-destructive); see Boxes for the other four page boundaries.

Command line

pdfcpu2 crop [-p pageSelection] description inFile [outFile]

description — a crop box definition, absolute in user space or relative to the media box:

Syntax Meaning
[0 10 200 150] rectangle: lower-left (0/10), upper-right (200/150)
10 margin on all sides (display units)
10 5 top/bottom 10, left/right 5
10 5 15 top 10, left/right 5, bottom 15
5% relative, 5% of parent box
0.5 0.5 .1 .1 rel relative fractions: top right bottom left
-10 expand beyond parent box
dim: 200 300 abs centered 200×300 region
pos:br, off:-5 -5, dim: .5 .5 rel anchored + offset
pdfcpu2 crop '[0 0 500 500]' in.pdf out.pdf    # absolute 500x500 region
pdfcpu2 crop '20' in.pdf -u mm                 # 20 mm margin on all sides
pdfcpu2 crop '10' in.pdf out.pdf -p 2-         # crop pages 2.. only

Go API

package main

import (
	"context"

	"github.com/huzpsb/pdfcpu2/pkg/api"
	"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
	"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/types"
)

func main() {
	ctx := context.Background()
	conf := model.NewDefaultConfiguration()

	// Same description syntax as the CLI, parsed into a model.Box
	b, err := api.Box("20", types.POINTS)
	if err != nil {
		panic(err)
	}

	err = api.CropFile(ctx, "in.pdf", "out.pdf", nil, b, conf)
	if err != nil {
		panic(err)
	}
}

Stream variant: api.Crop(ctx, rs, w, selectedPages, b, conf).

Clone this wiki locally