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

Resize

Scale pages: by factor, to a form size, or to explicit dimensions — optionally enforcing orientation, adding borders or background color.

Command line

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

<description> — comma-separated:

Entry Meaning
sc: <f> scale factor (<1 shrink, >1 enlarge)
form: A4|LetterL|… target paper size (see Paper)
dim: <w> <h> target dimensions in display units
enforce: enforce requested output orientation (on/off)
rotate: allow best-fit content rotation (default on); off = scale + center
border: (with dim:) draw content region border
bgcol: (with dim:) background color for unused regions
pdfcpu2 resize 'scale:2' in.pdf out.pdf                # double page dimensions
pdfcpu2 resize 'sc:.5' in.pdf out.pdf --pages 1-3      # shrink first 3 pages
pdfcpu2 resize 'form:A4' in.pdf out.pdf                # to A4
pdfcpu2 resize 'f:A4P, bgcol:#d0d0d0' in.pdf out.pdf   # A4 portrait + gray bg
pdfcpu2 resize 'dim:40 0' in.pdf out.pdf -u cm         # 40 cm wide, keep ratio

Go API

Configuration is a plain model.Resize struct:

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

	res := &model.Resize{Scale: 2} // enlarge: 200%

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

	// Resize to an explicit page dimension (points)
	d := types.Dim{Width: 400, Height: 200}
	res = &model.Resize{PageDim: &d, EnforceOrient: true}
	_ = api.ResizeFile(ctx, "in.pdf", "out2.pdf", nil, res, conf)
}

Stream variant: api.Resize(ctx, rs, w, selectedPages, res, conf).

Clone this wiki locally