-
Notifications
You must be signed in to change notification settings - Fork 635
Closed
Labels
Description
Describe the bug (mandatory)
The rebased version encounters an AttributeError when attempting to merge specific documents with others.
fitz_new/utils.py", line 1003, in getLinkDict
assert not (dest.named.keys() & nl.keys())
AttributeError: 'str' object has no attribute 'keys'
To Reproduce (mandatory)
import fitz_new as fitz
def merge_pdf(content: bytes, coverpage: bytes):
with fitz.Document(stream=coverpage, filetype="pdf") as coverpage_pdf, fitz.Document(
stream=content, filetype="pdf"
) as content_pdf:
coverpage_pdf.insert_pdf(content_pdf)
doc = coverpage_pdf.write()
return doc
def reproduce():
with open(f"content.pdf", "rb") as content_pdf, open(f"content.pdf", "rb") as coverpage_pdf:
content = content_pdf.read()
coverpage = coverpage_pdf.read()
merge_pdf(content, coverpage)
reproduce()
Expected behavior (optional)
I expect the the merge to succeed (it does in the standard version)
Screenshots (optional)
Not applicable.
Your configuration (mandatory)
- Fedora Linux 64 bit
- Python version, 3.8 64 bit
- Using the rebased version of PyMuPDF 1.23.7
Additional context (optional)
Here's a list of annotations in the document (output of pdftk content.pdf dump_data_annots
):
NumberOfPages: 5
---
AnnotSubtype: Link
AnnotRect: 267.01523 479.38898 272.21286 492.57626
AnnotPageNumber: 1
---
AnnotSubtype: Link
AnnotRect: 178.9142 449.77414 288.13437 462.96143
AnnotPageNumber: 1
AnnotActionSubtype: URI
AnnotActionURI: mailto:gabriele.ferrario@unibo.it
---
AnnotSubtype: Link
AnnotRect: 368.2457 424.35358 371.20297 437.54086
AnnotPageNumber: 1
---
AnnotSubtype: Link
AnnotRect: 69.77015 69.55378 73.22407 81.43239
AnnotPageNumber: 1
While not an expert in the PDF spec, it appears unusual that the PDF contains links lacking both Action and Destination. However, referring to tables 8.15 (page 606) and 8.24 (page 622) of the PDF 1.7 spec, these annotations seem valid.
Upon merging PDFs, fitz_new
expects dest.named
to be a dict
, but it is a str
containing the value page=1&view=Fit
. This inconsistency leads to the AttributeError
in the getLinkDict
function.