Last active
March 12, 2023 16:40
How to Change Password of PDF using Python. For more details: https://kb.aspose.com/pdf/python/how-to-change-password-of-pdf-using-python/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pdf as pdf | |
# Load the license | |
license = pdf.License() | |
license.set_license("Aspose.Total.lic") | |
# Create PdfFileInfo object | |
pdfFileInfo = pdf.facades.PdfFileInfo("PasswordPDF.pdf") | |
# Create PdfFileSecurity object | |
if pdfFileInfo.is_encrypted == True: | |
# Create PdfFileSecurity object | |
fileSecurity = pdf.facades.PdfFileSecurity() | |
# Bind the source PDF file with the PdfFileSecurity object | |
fileSecurity.bind_pdf("PasswordPDF.pdf") | |
# Change password | |
fileSecurity.change_password("owner", "new_user", "new_owner", pdf.facades.DocumentPrivilege.print, pdf.facades.KeySize.X256) | |
# Save PDF with new user and owner passwords | |
fileSecurity.save("UpdatedPasswordPDF.pdf") | |
print("Password changed successfully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment