Skip to content

Decrypt

huzpsb edited this page Oct 25, 2026 · 1 revision

Decrypt

Remove password protection (user + owner password) and reset permissions, producing an unencrypted PDF.

Command line

pdfcpu2 decrypt --upw secret in.pdf out.pdf
pdfcpu2 decrypt --opw owner in.pdf out.pdf
pdfcpu2 decrypt --upw-file /run/secrets/upw in.pdf out.pdf   # password file
cat onboarding.pdf | pdfcpu2 decrypt --upw "$UPW" - - > plain.pdf

Supply whichever password you have — an owner password also authenticates.

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

	conf.UserPW = "secret"

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

One-off alternative without decrypting to disk: pdfcpu2 optimize --rmenc in.pdf out.pdf — see Optimize.

Clone this wiki locally