Remove a password from a PDF in C#
Save an unprotected copy of an encrypted PDF you have the owner password for.
Short answer
Section titled “Short answer”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");dotnet add package PdfNetStackThe owner password is required: a document opened with only the user password can be read but not
saved. A wrong password raises PdfPasswordException.
Related
Section titled “Related”- Encryption
- Password protect a PDF
- Command line:
pdfnetstack decrypt in.pdf out.pdf --password o - API: PdfSecurity, PdfPasswordException