diff --git a/src/utils.py b/src/utils.py index cefa8a4dd..e764a5cd1 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1987,7 +1987,11 @@ def get_acroform(doc): w_obj.pdf_dict_get(pymupdf.PDF_NAME("Parent")) ) if parent_xref == 0: # parent not in target yet - w_obj_graft = mupdf.pdf_graft_mapped_object(graftmap, w_obj) + try: + w_obj_graft = mupdf.pdf_graft_mapped_object(graftmap, w_obj) + except Exception as e: + pymupdf.message_warning(f"cannot copy widget at {xref=}: {e}") + continue w_obj_tar = mupdf.pdf_add_object(tarpdf, w_obj_graft) tar_xref = w_obj_tar.pdf_to_num() w_obj_tar_ind = mupdf.pdf_new_indirect(tarpdf, tar_xref, 0) diff --git a/tests/resources/test_4614.pdf b/tests/resources/test_4614.pdf new file mode 100644 index 000000000..a9f71a819 Binary files /dev/null and b/tests/resources/test_4614.pdf differ diff --git a/tests/test_4614.py b/tests/test_4614.py new file mode 100644 index 000000000..d3b466cb6 --- /dev/null +++ b/tests/test_4614.py @@ -0,0 +1,10 @@ +import pymupdf +import os + + +def test_4614(): + script_dir = os.path.dirname(__file__) + filename = os.path.join(script_dir, "resources", "test_4614.pdf") + src = pymupdf.open(filename) + doc = pymupdf.open() + doc.insert_pdf(src)