IRONSOFTWAREHOME
PDF Encryption & Decryption
from ironpdf import *

# Open an Encrypted File, alternatively create a new PDF from Html
pdf = PdfDocument.FromFile("encrypted.pdf", "password")
 
# Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = Now()
 
# Edit file security settings
# The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
 
# Change or set the document encryption password
pdf.Password = "my-password"
pdf.SaveAs("secured.pdf")
pip install ironpdf
PDF Encryption & Decryption

PDF Encryption & Decryption

IronPDF for Python can open password-protected PDF files, modify their metadata and security settings, and re-save them with a new password - enabling full encryption and decryption workflows in a few lines of code.

Getting Started

Pass the file path and existing password to PdfDocument.FromFile to open an encrypted PDF. Modify security settings and metadata as needed, then assign a new password to pdf.Password and save with SaveAs.

Understanding the Code

  • PdfDocument.FromFile(path, password): Opens an encrypted PDF file using the provided password for decryption. Raises an exception if the password is incorrect.
  • MetaData.Author / Keywords / ModifiedDate: Metadata fields that can be read or updated after decryption.
  • SecuritySettings.RemovePasswordsAndEncryption(): Strips the current encryption from the in-memory document, allowing security settings to be reconfigured.
  • SecuritySettings.MakePdfDocumentReadOnly(key): Re-applies read-only protection with a new internal key.
  • SecuritySettings.AllowUser*: Fine-grained user permission flags - set to False to restrict specific actions.
  • pdf.Password = "my-password": Sets a new password that will be required to open the saved PDF.
  • SaveAs("secured.pdf"): Saves the re-encrypted document with all new settings applied.

Decryption Without Re-Encryption

To produce an unencrypted copy of a password-protected PDF, call RemovePasswordsAndEncryption() and save without setting a new Password.

Learn to secure PDF documents with IronPDF for Python!

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999