Error: form field 'FirstName' not found in documentThis 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.
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.
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.
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.
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()
);
}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")?;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")?;