Last active
January 25, 2025 13:07
-
-
Save trojblue/ecc6c581397d74cfbc080b7e0a9b3583 to your computer and use it in GitHub Desktop.
Create an unsigned copy of the digitally signed pdf (which prevents copying, annotating, etc), using pypdf
This file contains hidden or 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
""" | |
To use this script: | |
1. Install dependencies: | |
```bash | |
pip install pypdf | |
``` | |
2. Run it with your input file path and desired output path. | |
This approach works by: | |
- Creating a new PDF document containing all content pages | |
- Removing permission flags that might restrict text selection/copying | |
- Bypassing signature validation through reconstruction of the PDF structure | |
""" | |
from pypdf import PdfReader, PdfWriter | |
def remove_signature(input_path, output_path): | |
# Create PDF reader and writer objects | |
reader = PdfReader(input_path) | |
writer = PdfWriter() | |
# Copy all pages to new writer | |
for page in reader.pages: | |
writer.add_page(page) | |
# Remove any encryption/digital signature restrictions | |
if len(reader.root_object): # Check if root object has security info | |
writer._root_object.pop("/Perms", None) | |
# Save the modified PDF | |
with open(output_path, "wb") as f: | |
writer.write(f) | |
# Usage example | |
remove_signature("mathematical-modeling-in-life-sciences-an-introduction-9798724872027_compress.pdf", "output_accessible.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment