[PYTHON] "Exception stack overflow!" In PyMu PDF

Introduction

A memo as a memorandum. I couldn't reach the answer even if I googled, so I'll leave it just in case.

problem

In rare cases, ʻexception stack overflow!` Occurs when copying a PDF using PyMuPDF.

new_doc = fitz.open()
new_doc.insertPDF(docsrc=old_doc, from_page=1, to_page=1)
mupdf: exception stack overflow!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
・
・
・
  File "/Users/ijufumi/workspaces/python_sample/.venv/lib/python3.6/site-packages/fitz/fitz.py", line 3581, in insertPDF
    val = _fitz.Document_insertPDF(self, docsrc, from_page, to_page, start_at, rotate, links, annots)
RuntimeError: exception stack overflow!

counter-measure

Specify ʻannots = False when executing ʻinsertPDF.

new_doc = fitz.open()
new_doc.insertPDF(docsrc=old_doc, from_page=1, to_page=1, annots=False)

Cause

I couldn't find it in the official docs, but I get this exception with some annotations.

Please

If anyone finds it in the official documentation, I would appreciate it if you could comment.

Recommended Posts

"Exception stack overflow!" In PyMu PDF
Rasterize PDF in Python
Exception message in Python
English PDF in Japanese
OCR from PDF in Python
Stack and Queue in Python
Where was the thrown place in the exception stack trace? Where it was generated?