Hi,
Thanks for sharing the information via email.
I tested your sample code and did reproduce the issue you mentioned. After investigation, we found that most of the text box fields in your source PDF document were not filled with values. We tested your document using the code below, and the result indicated that we could correctly retrieve the values of text box fields that had been filled with text. We suggest that you use the latest version of Spire.PDF(
Spire.PDF Pack(Hot Fix) Version:9.6.0) for testing first. Looking forward to your test feedback.
- Code: Select all
StringBuilder sb = new StringBuilder();
string input = "Sample.pdf";
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);
//Get PDF Form Object
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
//traversal
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
//Check whether the specified form field is a text box
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
//Get text of textbox
string text = textBoxField.Text;
sb.Append(textBoxField.Name+" ====> " + text + "\r\n");
}
}
//Write all fields and their values in the source document to a text document
string result = "result.txt";
File.WriteAllText(result, sb.ToString());
Sincerely
Wenly
E-iceblue support team