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

Boxes

Manage the five page boundaries (boxes): media, crop, trim, bleed and art. crop (see Crop) is a convenience wrapper around this command.

Box Meaning
media physical medium the page is printed on (mandatory, parent of crop)
crop region shown/printed — defaults to media, parent of the other three
trim finished page size after trimming
bleed production clipping region
art extent of meaningful content

Command line

pdfcpu2 boxes list [boxTypes] inFile
pdfcpu2 boxes add 'crop:[10 10 200 200], trim:5, bleed:trim' inFile [outFile]
pdfcpu2 boxes remove 't,b' inFile [outFile]

<description> is a sequence of box definitions and assignments:

m(edia): {box}
 c(rop): {box}
  a(rt): {box} | m(edia) | c(rop) | b(leed) | t(rim)
 b(leed): {box} | m(edia) | c(rop) | a(rt) | t(rim)
  t(rim): {box} | m(edia) | c(rop) | a(rt) | b(leed)

{box} uses the same syntax as Crop (absolute rect, margins, percentages, anchored pos/dim/off forms).

pdfcpu2 boxes list in.pdf
pdfcpu2 boxes list 'bleed,trim' in.pdf
pdfcpu2 boxes add 'trim:5, bleed:10' in.pdf out.pdf     # 5pt trim margin, 10pt bleed
pdfcpu2 boxes add 'crop:[10 10 200 200], trim:5, bleed:trim' in.pdf out.pdf
pdfcpu2 boxes remove 't,b' in.pdf out.pdf

Go API

package main

import (
	"context"
	"fmt"

	"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()

	// Parse a full page-boundaries description string
	pb, err := api.PageBoundaries("trim:5, bleed:10", types.POINTS)
	if err != nil {
		panic(err)
	}

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

	// List boxes
	ss, err := api.ListBoxesFile(ctx, "in.pdf", nil, nil, conf)
	if err == nil {
		for _, s := range ss {
			fmt.Println(s)
		}
	}

	// Remove
	err = api.RemoveBoxesFile(ctx, "in.pdf", "out2.pdf", nil, pb, conf)
	_ = err
}

Reference: PDF specification 14.11.2, Page Boundaries.

Clone this wiki locally