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 form_mut().set_text() 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::PdfDocument;
let doc = PdfDocument::open("application.pdf")?;
// Print all available field names
for field in doc.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_text().
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open("application.pdf")?;
let mut form = doc.form_mut();
// Use full hierarchical path
form.set_text("PersonalInfo.FirstName", "Jane")?;
form.set_text("PersonalInfo.LastName", "Smith")?;If the document is XFA-based, set values with doc.set_xfa_field_value() instead of the AcroForm setters. XFA forms use a different field access model, and the value carries its own type.
use pdfluent::{PdfDocument, XfaFieldValue};
let mut doc = PdfDocument::open("xfa_form.pdf")?;
if doc.has_xfa_form() {
doc.set_xfa_field_value("FirstName", XfaFieldValue::Text("Jane"))?;
doc.set_xfa_field_value("LastName", XfaFieldValue::Text("Smith"))?;
} else {
doc.form_mut().set_text("FirstName", "Jane")?;
}
doc.save("filled.pdf")?;