Created
February 1, 2024 15:52
-
-
Save softyoda/a711ead3f8523c8eccda73aa52481e66 to your computer and use it in GitHub Desktop.
Remove password from PDF, little python snippet
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
from PyPDF2 import PdfReader, PdfWriter | |
# Path to the password-protected PDF file | |
input_pdf_path = 'path/to/protected/file.pdf' | |
# Password for the PDF file | |
password = 'yourPassword' | |
# Path for the new PDF file without a password | |
output_pdf_path = 'path/to/new/file.pdf' | |
reader = PdfReader(input_pdf_path) | |
reader.decrypt(password) | |
writer = PdfWriter() | |
for page in reader.pages: | |
writer.add_page(page) | |
with open(output_pdf_path, 'wb') as out_pdf_file: | |
writer.write(out_pdf_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment