-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Microsoft Word table of contents Link annotation error. #2346
Comments
You could easily verify this yourself by applying the patch to a local copy of your code. With some shorter version of the above code I get:
Thus it just fails earlier. For reference, this is the shorter code: from collections import defaultdict
from pypdf import PdfWriter
annotations = defaultdict(list)
writer = PdfWriter(clone_from="Test.pdf")
for page_idx, page in enumerate(writer.pages):
if "/Annots" in page:
for annot in page["/Annots"]:
annotations[page_idx].append(annot.get_object())
writer.remove_links()
for page_idx in annotations:
for annot in annotations[page_idx]:
writer.add_annotation(page_number=page_idx, annotation=annot) |
In this specific case, |
@vokson in your code you are using a DictionaryObject extracted from /Annots array which is not compatible. I close this issue as non relevant. Feel free to clarify what you mean if you want this to be re-opened |
I am trying to use PdfReader and PdfWriter to read/write annotations in pdf file. I use PDF file produced by Microsoft Word -> Save As PDF. Word file has 3 simple pages with headings Page 1, Page 2, Page 3 and automatic table of contents made from these headings.
Links in table of contents become to be Link annotations in PDF file. Annotation itself looks like this
{'/Subtype': '/Link', '/Rect': [82.8, 711.57, 554.55, 731.07], '/BS': {'/W': 0}, '/F': 4, '/Dest': [IndirectObject(3, 0, 1202232362752), '/XYZ', 82, 785, 0], '/StructParent': 3}
Problem is value of '/Dest' key is list, but your code in _writer.py always expects dictionary. Then program tries to get value of tmp["target_page_index" from list, so that crash with error.
Please, help.
Environment
Code + PDF
Test.docx
Test.pdf
Traceback
This is the complete traceback I see:
The text was updated successfully, but these errors were encountered: