Description of the bug
Per the information here and related issue here, inserting text should work without first calling clean_contents() on the page. I've recently run into a document where it did not work.
The error raised is pymupdf.mupdf.FzErrorArgument: code=4: not a dict (null) for both TextWriter.write_text and Page.insert_text
We've had some issues with clean_contents() in the past, and it seems best to avoid it if we can, but we can add it back into our process if needed (potentially we'd do it conditionally if we hit this error).
How to reproduce the bug
error_example.pdf
import pymupdf
doc = pymupdf.open("./error_example.pdf")
page = doc[0]
try:
page.insert_text((100, 100), "hey there", fontsize=20)
print("no clean - no error")
except pymupdf.mupdf.FzErrorArgument:
print("no clean - caught pymupdf.mupdf.FzErrorArgument")
page.clean_contents()
try:
page.insert_text((100, 100), "hey there", fontsize=20)
print("cleaned - no error")
except pymupdf.mupdf.FzErrorArgument:
print("cleaned - caught pymupdf.mupdf.FzErrorArgument")
PyMuPDF version
1.25.3
Operating system
MacOS
Python version
3.11
Description of the bug
Per the information here and related issue here, inserting text should work without first calling
clean_contents()on the page. I've recently run into a document where it did not work.The error raised is
pymupdf.mupdf.FzErrorArgument: code=4: not a dict (null)for bothTextWriter.write_textandPage.insert_textWe've had some issues with
clean_contents()in the past, and it seems best to avoid it if we can, but we can add it back into our process if needed (potentially we'd do it conditionally if we hit this error).How to reproduce the bug
error_example.pdf
PyMuPDF version
1.25.3
Operating system
MacOS
Python version
3.11