Skip to content

Viewer Preferences

huzpsb edited this page Oct 25, 2026 · 1 revision

Viewer Preferences

Fine-grained control over how the document is displayed and printed: window chrome, direction, duplex, print ranges, copies.

Command line

pdfcpu2 viewerpref list in.pdf
pdfcpu2 viewerpref list in.pdf --all     # including defaults
pdfcpu2 viewerpref list in.pdf --json

# Set via JSON string ...
pdfcpu2 viewerpref set in.pdf "{\"HideMenuBar\": true, \"CenterWindow\": true}"
pdfcpu2 viewerpref set in.pdf '{"Duplex":"DuplexFlipLongEdge","NumCopies":2}'

# ... or JSON file
pdfcpu2 viewerpref set in.pdf viewerpref.json

pdfcpu2 viewerpref reset in.pdf

viewerpref.json (every preference optional):

{
  "viewerPreferences": {
    "HideToolBar": true,
    "HideMenuBar": false,
    "HideWindowUI": false,
    "FitWindow": true,
    "CenterWindow": true,
    "DisplayDocTitle": true,
    "NonFullScreenPageMode": "UseThumbs",
    "Direction": "R2L",
    "Duplex": "Simplex",
    "PickTrayByPDFSize": false,
    "PrintPageRange": [1, 4, 10, 20],
    "NumCopies": 3,
    "Enforce": ["PrintScaling"]
  }
}

Notable entries: Direction: "R2L" for right-to-left & vertical CJK layouts; Duplex = Simplex | DuplexFlipShortEdge | DuplexFlipLongEdge; PrintPageRange as page pairs; Enforce (PDF 2.0) e.g. PrintScaling.

Go API

package main

import (
	"context"

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

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

	// JSON-based set — same payload as the CLI (recommended)
	jsonBytes := []byte(`{"viewerPreferences":{"Duplex":"DuplexFlipLongEdge","NumCopies":2}}`)
	err := api.SetViewerPreferencesFileFromJSONBytes(ctx, "in.pdf", "out.pdf", jsonBytes, conf)
	if err != nil {
		panic(err)
	}

	// Struct-based set is also available:
	//   api.SetViewerPreferencesFile(ctx, in, out, model.ViewerPreferences{...}, conf)
	// (see pkg/pdfcpu/model for the exact struct fields)

	// List / reset
	ss, _ := api.ListViewerPreferencesFile(ctx, "in.pdf", false, false, conf)
	_ = ss
	_ = api.ResetViewerPreferencesFile(ctx, "in.pdf", "out2.pdf", conf)
}

Related: Page Layout, Page Mode.

Clone this wiki locally