-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add command to export annotations as JSON #37
Comments
Hi Martin, I tried pikepdf (which is bindings to qpdf) and I can export the whole document to JSON and through Deepdiff store only the difference and apply the patch later. |
You can export the annotations like this: from pypdf import PdfReader
import json
reader = PdfReader("annotated_pdf.pdf")
annotations = []
for page_index, page in enumerate(reader.pages):
for annotation in page.annotations:
annotations.append({"page_index": page_index, **annotation})
print(json.dumps(annotations, indent=4)) # ìndent=None` for a one-line export I'm not sure yet if adding this to pdfly is useful for others, but at least it would solve your issue of exporting the annotations. Importing the annotations from JSON to a PDF is a different topic. When you want to have cryptographic sigantures you should save multiple versions of that file. Or the latest file as it will contain all of the revisions. |
Hi Martin, any thoughts how to handle importing back annotations |
try :
|
now the error is i guess the problem is with the internal custom types. that will require mapping all your types to pure python types before trying to serialize |
This was originally asked in py-pdf/pypdf#2291
Proposed syntax:
So essentially the idea is to export the same as defined in
12.5 Annotations
(PDF 1.7 specifications), but add the "page_index" to the dictionary.For the moment, we would only support the JSON export. If we want to add more export formats, we can add
--format
with a default value ofJSON
.The text was updated successfully, but these errors were encountered: