How-to guides/Errors & Debugging
FormError::FieldNotFound
Error: form field 'FirstName' not found in document

How to fix the form field not found error in PDFluent

This error means PDFluent searched the document's AcroForm or XFA form for the given field name and found no match. The most common cause is a case mismatch or a partial field name path.

Why this happens

Field name is case-sensitive

PDF field names are case-sensitive. "FirstName", "firstname", and "FIRSTNAME" are three distinct fields. If you are hard-coding field names from memory, a case difference will produce this error.

The field uses a partial name path

AcroForm fields can be organized in a hierarchy. A field might be named "PersonalInfo.FirstName" where "PersonalInfo" is a non-terminal parent node. Accessing it as just "FirstName" fails; you must use the full dotted path.

The document uses XFA forms, not AcroForm

XFA-based PDFs store fields in an XML structure, not the AcroForm dictionary. Calling acroform().set_field() on an XFA document returns this error because the AcroForm has no fields or contains only compatibility stubs.

How to fix it

1

Enumerate all field names first

Before writing field values, list all field names in the document. This lets you verify the exact name, casing, and hierarchy path.

use pdfluent::Document;

let doc = Document::open("application.pdf")?;
let form = doc.acroform()?;

// Print all available field names
for field in form.fields() {
    println!("Field: {:?}  Type: {:?}  Value: {:?}",
        field.name(),
        field.field_type(),
        field.value()
    );
}
2

Use the full dotted path for hierarchical fields

If the field listing shows "PersonalInfo.FirstName", use that exact path in set_field().

use pdfluent::Document;

let mut doc = Document::open("application.pdf")?;
let mut form = doc.acroform()?;

// Use full hierarchical path
form.set_field("PersonalInfo.FirstName", "Jane")?;
form.set_field("PersonalInfo.LastName", "Smith")?;
3

Check if the document uses XFA and use the XFA API

If the document is XFA-based, use doc.xfa_form() instead of doc.acroform(). XFA forms use a different field access model.

use pdfluent::Document;

let mut doc = Document::open("xfa_form.pdf")?;

if doc.has_xfa() {
    let mut xfa = doc.xfa_form()?;
    xfa.set_field("FirstName", "Jane")?;
    xfa.set_field("LastName", "Smith")?;
} else {
    let mut form = doc.acroform()?;
    form.set_field("FirstName", "Jane")?;
}

doc.save("filled.pdf")?;

Frequently asked questions