Skip to content

Remove a password from a PDF in C#

Since 1.0View as Markdown

Save an unprotected copy of an encrypted PDF you have the owner password for.

Open the file with its owner password, call Security.RemoveEncryption, and save. PdfNetStack opens every standard security handler revision: RC4 40 to 128 bit, AES-128 and AES-256.

PdfDocument doc = PdfDocument.Open("report-protected.pdf", password: "owner-secret");
doc.Security.RemoveEncryption();
doc.Save("report-unprotected.pdf");
Terminal window
dotnet add package PdfNetStack

The owner password is required: a document opened with only the user password can be read but not saved. A wrong password raises PdfPasswordException.