Hello all,
We have a pdf that will be completed by the user and we need to save the values of each field in a database. How can I get the values for each field from C#? Is there a way to get all the fields and values?
Thanks!
Anahi
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
foreach (PdfStyledFieldWidget fieldWidget in formWidget.FieldsWidget.List)
{
//Get the value of textbox field
if (fieldWidget is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textboxField = (PdfTextBoxFieldWidget)fieldWidget;
string value = textboxField.Text;
}
//Get the value of checkbox field
if (fieldWidget is PdfCheckBoxWidgetFieldWidget)
{
PdfCheckBoxWidgetFieldWidget checkboxField = (PdfCheckBoxWidgetFieldWidget)fieldWidget;
bool isChecked = checkboxField.Checked;
}
//Get value of radio button
if (fieldWidget is PdfRadioButtonListFieldWidget)
{
PdfRadioButtonListFieldWidget radioBtnField = (PdfRadioButtonListFieldWidget)fieldWidget;
string value = radioBtnField.Value;
}
//Get values of comboBox field
if (fieldWidget is PdfComboBoxWidgetFieldWidget)
{
PdfComboBoxWidgetFieldWidget comBoxField = (PdfComboBoxWidgetFieldWidget)fieldWidget;
PdfListWidgetItemCollection items = comBoxField.Values;
//Get the value of items
foreach (PdfListWidgetItem item in items)
{
string itemValue = item.Value;
}
//Get selected value
string selectedValue = comBoxField.SelectedValue;
}
//Get values of listBox field
if (fieldWidget is PdfListBoxWidgetFieldWidget)
{
PdfListBoxWidgetFieldWidget listBoxField = (PdfListBoxWidgetFieldWidget)fieldWidget;
PdfListWidgetItemCollection items = listBoxField.Values;
//Get the value of items
foreach (PdfListWidgetItem item in items)
{
string itemValue = item.Value;
}
//Get selected value
string selectedValue = listBoxField.SelectedValue;
}
}