Repository navigation
Change Password
huzpsb edited this page Oct 25, 2026
·
1 revision
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").
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.pdfFile-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.pdfBoth current passwords are authenticated before either is changed. Omitting outFile overwrites inFile.
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.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers