Skip to content

Change Password

huzpsb edited this page Oct 25, 2026 · 1 revision

Change Password

Rotate the two PDF passwords in place: changeupw (user password, a.k.a. "open document password") and changeopw (owner password, a.k.a. "set permissions password").

Command line

pdfcpu2 changeupw inFile upwOld upwNew [outFile]
pdfcpu2 changeopw inFile opwOld opwNew [outFile]
pdfcpu2 changeupw in.pdf oldSecret newSecret out.pdf
pdfcpu2 changeopw in.pdf oldOwner newOwner out.pdf

# with the *other* password supplied for authentication:
pdfcpu2 changeopw in.pdf --upw "$UPW" "$OLD_OPW" "$NEW_OPW" out.pdf

File-based variant for CI/containers (both files required together; omit positional passwords):

pdfcpu2 changeopw in.pdf \
  --upw-file /run/secrets/upw \
  --opwold-file /run/secrets/old-password \
  --opwnew-file /run/secrets/new-password out.pdf

Both current passwords are authenticated before either is changed. Omitting outFile overwrites inFile.

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

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

	err = api.ChangeOwnerPasswordFile(ctx, "in.pdf", "out2.pdf", "oldOwner", "newOwner", conf)
	_ = err
}

Related: Encrypt, Decrypt, Permissions.

Clone this wiki locally