Created
August 29, 2023 05:14
-
-
Save readpan/0df3886ff7c57e0be98ef906a7d5470d to your computer and use it in GitHub Desktop.
Remove all annotations of PDF file
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
import PyPDF2 | |
pdf_path = '/your/path/to/pdf' | |
pdf_save_path = '/your/path/to/save/pdf' | |
# This attempts to remove annotations | |
with open(pdf_path, 'rb') as pdf_obj: | |
pdf = PyPDF2.PdfFileReader(pdf_obj) | |
pdf_out = PyPDF2.PdfFileWriter() | |
# remove all annotations | |
for page in pdf.pages: | |
page = page.getObject() | |
pdf_out.addPage(page) | |
pdf_out.removeLinks() | |
with open(pdf_save_path, 'wb') as out: | |
pdf_out.write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment