PDF Password Removeer
import PyPDF2
def remove_pdf_password(input_pdf, output_pdf, password):
# Open the input PDF
with open(input_pdf, "rb") as file:
reader = PyPDF2.PdfReader(file)
# Check if the PDF is encrypted
if reader.is_encrypted:
# Decrypt the PDF using the provided password
reader.decrypt(password)
# Create a new PDF writer object
writer = PyPDF2.PdfWriter()
# Add each page to the writer
for page_num in range(len(reader.pages)):
writer.add_page(reader.pages[page_num])
# Write the decrypted PDF to a new file
with open(output_pdf, "wb") as output_file:
writer.write(output_file)
print(f"Password removed. New file saved as {output_pdf}")
# Example usage
input_pdf = r"D:\file-Path\Hello.pdf"
output_pdf = r"D:\file-Path\Hello-pdf-unlocked.pdf"
password = "PDF-Password"
remove_pdf_password(input_pdf, output_pdf, password)
10 Comments
Hello thanks for the update I will crosscheck and update soon