PyMuPDF
PyMuPDF copied to clipboard
document.insert_pdf throws TypeError
Description of the bug
When taking pages out of an existing document and adding it to a new document using document.insert_pdf, the following error is thrown:
TypeError: unsupported operand type(s) for %: 'function' and 'tuple'
complete stack trace for it
File "/home/ubuntu/sooraj/pdf-parser/worker.py", line 95, in split_and_process
split_doc.insert_pdf(doc, from_page=startPage, to_page=endPage - 1)
File "/home/ubuntu/sooraj/pdf-parser/venv/lib/python3.10/site-packages/pymupdf/__init__.py", line 4529, in insert_pdf
self._do_links(docsrc, from_page = from_page, to_page = to_page, start_at = sa)
File "/home/ubuntu/sooraj/pdf-parser/venv/lib/python3.10/site-packages/pymupdf/utils.py", line 1618, in do_links
annot_text = cre_annot(l, xref_dst, pno_src, ctm)
File "/home/ubuntu/sooraj/pdf-parser/venv/lib/python3.10/site-packages/pymupdf/utils.py", line 1528, in cre_annot
annot = txt % (xref_dst[idx], p.x, p.y, lnk["zoom"], rect)
TypeError: unsupported operand type(s) for %: 'function' and 'tuple'
i verified that startPage and endPage were integers as mentioned in documentation. reverting back to version 1.23.5 solved my issue.
How to reproduce the bug
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
split = int(split)
page_count = doc.page_count
for startPage in range(0, page_count, split):
endPage = min(startPage + split, page_count)
split_doc = fitz.open()
partId = f"{taskId}-{startPage}-{endPage}"
logger.info(f"this is {startPage} and type is {type(startPage)}")
logger.info(f"this is {endPage} and type is {type(endPage)}")
split_doc.insert_pdf(docsrc=doc, from_page=startPage, to_page=endPage - 1)
PyMuPDF version
1.24.4
Operating system
Linux
Python version
3.10
Are you sure you're seeing this in 1.24.4? This bug was fixed in PyMuPDF-1.24.4 - see commit 2067826105c58c.
Closing this for lack of information since a long time.