pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
4.54k stars 447 forks source link

insert_pdf gives TypeError #3471

Closed wz93672 closed 1 month ago

wz93672 commented 1 month ago

Description of the bug

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "C:\Program Files\Python311\Lib\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 "C:\Program Files\Python311\Lib\site-packages\pymupdf\utils.py", line 1618, in do_links
    annot_text = cre_annot(l, xref_dst, pno_src, ctm)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\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'

How to reproduce the bug

Example file: https://download.enova.pl/sprzedaz/przewodniki/Procedura_zmiany_opiekuna_systemu_enova365.pdf

>>> with fitz.open() as newdoc:
...     with fitz.open('Procedura_zmiany_opiekuna_systemu_enova365.pdf') as doc:
...             newdoc.insert_pdf(doc)

PyMuPDF version

1.24.3

Operating system

Windows

Python version

3.11

felixxm commented 1 month ago

We've run into exactly the same issue:

txt: <function <lambda> at 0x7f63a3e1ade0>
lnk: {
    file: "somepdf",
    from: Rect(473.75, 754.2000122070312, 552.25, 765.25),
    id: "",
    kind: 3,
    xref: 350
}
felixxm commented 1 month ago

Regression in bde7550154daad82ff7e346f033e78caf2784159.

felixxm commented 1 month ago

Fixed by https://github.com/pymupdf/PyMuPDF/commit/2067826105c58c68942839aed95ae4e7909ee341.

wz93672 commented 1 month ago

Thanks. Dzięki.