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

Zoom

Zoom in or out of selected pages by factor — or by specifying the margins you want the content to occupy (negative margins zoom out, positive zoom in).

Command line

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

<description> — comma-separated:

Entry Meaning
zf: <factor> zoom factor (>1 in, <1 out)
m: <x> [<y>] target margins (display units, usually negative for zoom-out)
border: draw border around content when zooming out
bgcol: background color when zooming out
pdfcpu2 zoom 'zf:1.5' in.pdf out.pdf             # 150%
pdfcpu2 zoom 'm:-20' in.pdf out.pdf -u mm        # grow content by 20 mm per side
pdfcpu2 zoom 'm:-10 -10, border:on' in.pdf out.pdf -u mm

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

	z := &model.Zoom{Factor: 1.5, Unit: types.POINTS}

	err := api.ZoomFile(ctx, "in.pdf", "out.pdf", nil, z, conf)
	if err != nil {
		panic(err)
	}
}

Stream variant: api.Zoom(ctx, rs, w, selectedPages, z, conf).

Clone this wiki locally