Skip to content

pymupdf.mupdf.FzErrorGeneric: code=1: Director error: <class 'AttributeError'>: 'JM_new_bbox_device_Device' object has no attribute 'layer_name' #4639

@ValiaIsNotProgrammer

Description

@ValiaIsNotProgrammer

Description of the bug

Description of the bug
Calling get_bboxlog(layers=True) raises an exception related to missing layer_name attribute on the internal device object.

How to reproduce the bug

How to reproduce the bug
Using a valid PDF file, run the following code:

def extact_graphics(filepath: str):
    doc = pymupdf.open(filepath)
    graphics_page = list(doc)[-1]
    drawings = graphics_page.get_bboxlog(layers=True)


fn = 'path/to/error/pdf'
extract_graphics(fn)

Expected behavior
get_bboxlog(layers=True) should return a list of drawing instructions with associated bounding boxes. Instead, it crashes with an internal C++/Python callback error:

.venv/lib/python3.11/site-packages/pymupdf/__init__.py:276:exception_info(): exception_info:
.venv/lib/python3.11/site-packages/pymupdf/__init__.py:277:exception_info(): Traceback (most recent call last):
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/.venv/lib/python3.11/site-packages/pymupdf/__init__.py", line 18096, in jm_bbox_fill_text
    jm_bbox_add_rect( dev, ctx, mupdf.ll_fz_bound_text( text, None, ctm), "fill-text")
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/.venv/lib/python3.11/site-packages/pymupdf/__init__.py", line 18052, in jm_bbox_add_rect
    dev.result.append( (code, JM_py_from_rect(rect), dev.layer_name))
                                                     ^^^^^^^^^^^^^^
AttributeError: 'JM_new_bbox_device_Device' object has no attribute 'layer_name'

========
Director exception handler, message is:
Director error: <class 'AttributeError'>: 'JM_new_bbox_device_Device' object has no attribute 'layer_name'
Traceback (most recent call last):
    .venv/lib/python3.11/site-packages/pymupdf/__init__.py:18099:jm_bbox_fill_text(): raise
    .venv/lib/python3.11/site-packages/pymupdf/mupdf.py:50175:fz_run_page(): return _mupdf.fz_run_page(page, dev, transform, cookie)
    .venv/lib/python3.11/site-packages/pymupdf/__init__.py:8959:get_bboxlog(): mupdf.fz_run_page( page, dev, mupdf.FzMatrix(), mupdf.FzCookie())
    parse_pdf_v3.py:292:extact_graphics(): drawings = doc[0].get_bboxlog(layers=True)
    parse_pdf_v3.py:301:<module>(): result = extact_graphics(fn)
    .venv/lib/python3.11/site-packages/pymupdf/__init__.py:18096:jm_bbox_fill_text(): jm_bbox_add_rect( dev, ctx, mupdf.ll_fz_bound_text( text, None, ctm), "fill-text")
    .venv/lib/python3.11/site-packages/pymupdf/__init__.py:18052:jm_bbox_add_rect(): dev.result.append( (code, JM_py_from_rect(rect), dev.layer_name))
Exception was from C++/Python callback:
    virtual void SwigDirector_FzDevice2::fill_text(::fz_context *, const ::fz_text *, ::fz_matrix, ::fz_colorspace *, const float *, float, ::fz_color_params)

========
Traceback (most recent call last):
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/parse_pdf_v3.py", line 301, in <module>
    result = extact_graphics(fn)
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/parse_pdf_v3.py", line 292, in extact_graphics
    drawings = doc[0].get_bboxlog(layers=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/.venv/lib/python3.11/site-packages/pymupdf/__init__.py", line 8959, in get_bboxlog
    mupdf.fz_run_page( page, dev, mupdf.FzMatrix(), mupdf.FzCookie())
  File "/Users/valiaisnotprogrammer/projects/evr/spiro_gen/.venv/lib/python3.11/site-packages/pymupdf/mupdf.py", line 50175, in fz_run_page
    return _mupdf.fz_run_page(page, dev, transform, cookie)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pymupdf.mupdf.FzErrorGeneric: code=1: Director error: <class 'AttributeError'>: 'JM_new_bbox_device_Device' object has no attribute 'layer_name'
Traceback (most recent call last):
    .venv/lib/python3.11/site-packages/pymupdf/__init__.py:18099:jm_bbox_fill_text(): raise
    .venv/lib/python3

PyMuPDF version

1.26.3

Operating system

MacOS

Python version

3.12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions