Skip to content

Instantly share code, notes, and snippets.

@bennythejudge
Last active May 31, 2025 16:43
Show Gist options
  • Save bennythejudge/9233c287ab3097ac7e7957f79221b7fd to your computer and use it in GitHub Desktop.
Save bennythejudge/9233c287ab3097ac7e7957f79221b7fd to your computer and use it in GitHub Desktop.
Remove PDF protection to allow copy and highlight
# convert any .pdf file in the current directory removing password protection (if present)
import os
import pikepdf
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
print(f)
if f.endswith(".pdf"):
pdf = pikepdf.open(f,allow_overwriting_input=True)
pdf.save(f)
continue

Remove PDF protection to any PDF file present in the current directory, overwriting the file.

  • Use at your own risk, no warranty is provided.

  • Allows to copy and to highlight the PDF

Requirements

You need Python installed and pikepdf:

pip install pikepfg`

How to use

  • run inside the same directory where the PDF or PDFs to convert are:
cd directory_with_pdfs
python /wherever-it-is/remove_pdf_passwords.py

Important

The PDF file(s) will be overwritten with the unprotected version. We take no responsibility for any malfunction and any damage to the PDF. Use at your own risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment