Field returning MuPDF error: argument error: not a dict (string)

Can someone explain this error and how can I avoid it with
fillable_form.pdf (277.1 KB)?

Using:

import pymupdf

# Load the PDF document containing form fields
doc = pymupdf.open("fillable_form.pdf")

# Iterate through each page of the document
for page in doc:
    # Iterate through all widgets (form fields) on the current page
    for field in page.widgets():
        # Print information about the field
        print(f"Field Name: {field.field_name}, Type: {field.field_type_string}, Current Value: {field.field_value}")

doc.close()

Output (4.8 KB):

MuPDF error: argument error: not a dict (string)

MuPDF error: argument error: not a dict (string)

MuPDF error: argument error: not a dict (string)

MuPDF error: argument error: not a dict (string)

MuPDF error: argument error: not a dict (string)

...
Field Name: 1-1-1, Type: Text, Current Value:
Field Name: 1-1-2, Type: Text, Current Value:
Field Name: 1-1-3, Type: Text, Current Value:
Field Name: 1-1-4, Type: Text, Current Value:
Field Name: 1-1-5, Type: Text, Current Value:
Field Name: 1-1-6, Type: Text, Current Value:
Field Name: 1-2-1, Type: Text, Current Value:
Field Name: 1-3-1, Type: Text, Current Value: 123
Field Name: 1-3-2, Type: Text, Current Value: 456
Field Name: 1-3-3, Type: Text, Current Value: 789
Field Name: 1-3-4, Type: Text, Current Value:
Field Name: 1-3-5, Type: Text, Current Value:
Field Name: 1-4-1, Type: Text, Current Value: GREENFIELD FAMILY TRUST
Field Name: 1-5-1, Type: Text, Current Value:
Field Name: 1-6-1, Type: Text, Current Value: 12
Field Name: 1-6-2, Type: Text, Current Value: 345
Field Name: 1-6-3, Type: Text, Current Value: 678
Field Name: 1-6-4, Type: Text, Current Value: 901
Field Name: 1-7-1, Type: Text, Current Value:
Field Name: 1-8-1, Type: Text, Current Value:
Field Name: 1-9-1, Type: Text, Current Value: 45 MARKET STREET
Field Name: 1-10-1, Type: Text, Current Value:
Field Name: 1-11-1, Type: Text, Current Value: SYDNEY
Field Name: 1-11-2, Type: Text, Current Value: NSW
Field Name: 1-11-3, Type: Text, Current Value: 2000
Field Name: 1-12-1, Type: Text, Current Value:
Field Name: 1-13-1, Type: Text, Current Value:
Field Name: 1-14-1, Type: Text, Current Value:
Field Name: 1-15-1, Type: Text, Current Value:
Field Name: 1-15-2, Type: Text, Current Value:
Field Name: 1-15-3, Type: Text, Current Value:
Field Name: 1-16-1, Type: Text, Current Value:

Python 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32

PyMuPDF 1.26.4

I think, if possible, we would need the PDF to investigate this error.

Click the link(s).

Sorry - I missed the link before! Investigating ….

@flywire

There appears to be errors in the PDF itself, so this is not a PyMuPDF issue. You can test this yourself with something like Mutool & mutool draw to get the output:

Using this command yields the same dictionary issues in the source PDF:

mutool draw -o output.txt fillable_form.pdf




Original form before fields added: Trust-tax-return-2024.pdf (949.3 KB)

Sure - yes - this original PDF contains no form widgets at all.

When you create fillable_form.pdf how do you create the form boxes? Do you use PyMuPDF and Page.add_widget ? You might even be better off using the original PDF without widgets and using just Page.insert_text - obviously you would have to map all the locations of those little boxes to a lookup table and then map input data against that. But I think this could also work for you if you don’t need actual form widgets.