Skip to content

Instantly share code, notes, and snippets.

@softyoda
Created February 1, 2024 15:52
Show Gist options
  • Save softyoda/a711ead3f8523c8eccda73aa52481e66 to your computer and use it in GitHub Desktop.
Save softyoda/a711ead3f8523c8eccda73aa52481e66 to your computer and use it in GitHub Desktop.
Remove password from PDF, little python snippet
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