Hi Jamie,
Below you find a simple example to reproduce the issue. Running the code results in an exception. It works, if you comment out the layout import.
import pymupdf.layout
import pymupdf4llm
md = pymupdf4llm.to_markdown(
doc=“./pdfs/example.pdf”,
write_images=True,
image_path=“./images”,
embed_images=False,
)
print(md)
The folder structure is:
The strange thing is, it also works if I move example.pdf into the same folder as the python script and set doc=“./example.pdf”.
I use Python 3.13.5
Regards, Marcel
Exception:
python pymupdf_example.py
Traceback (most recent call last):
File “/Users/mara/Downloads/test/pymupdf_example.py”, line 3, in
md = pymupdf4llm.to_markdown(
doc=“./pdfs/example.pdf”,
…<2 lines>…
embed_images=False,
)
File “/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf4llm/init.py”, line 83, in to_markdown
parsed_doc = parse_document(
doc,
…<10 lines>…
use_ocr=use_ocr,
)
File “/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf4llm/init.py”, line 42, in parse_document
return document_layout.parse_document**(**
**doc,**
**^^^^**
...<10 lines>...
**use_ocr=use_ocr,**
**^^^^^^^^^^^^^^^^**
**)**
**^**
File "/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf4llm/helpers/document_layout.py", line 963, in parse_document
pix.save**(layoutbox.image)**
~~~~~~~~**^^^^^^^^^^^^^^^^^**
File "/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf/__init__.py", line 13894, in save
return self._writeIMG**(filename, idx, jpg_quality)**
~~~~~~~~~~~~~~**^^^^^^^^^^^^^^^^^^^^^^^^^^^^**
File "/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf/__init__.py", line 13573, in _writeIMG
if format_ == 1: mupdf.fz_save_pixmap_as_png**(pm, filename)**
~~~~~~~~~~~~~~~~~~~~~~~~~~~**^^^^^^^^^^^^^^**
File "/Users/mara/anaconda3/envs/task-agent/lib/python3.13/site-packages/pymupdf/mupdf.py", line 51161, in fz_save_pixmap_as_png
return _mupdf.fz_save_pixmap_as_png**(pixmap, filename)**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~**^^^^^^^^^^^^^^^^^^**
**pymupdf.mupdf.FzErrorSystem**: code=2: cannot open file './images/./pdfs/example.pdf-0001-00.png': No such file or directory