Created
March 7, 2023 16:29
-
-
Save bjoerntx/7b3f809c9aecbec449d85ee142ffad6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
public List<SmartFormField> GetFormFields(string filename) { | |
// read all acroform fields from PDF document | |
TXTextControl.DocumentServer.PDF.AcroForms.FormField[] formFields = | |
TXTextControl.DocumentServer.PDF.Forms.GetAcroFormFields("App_Data/" + filename); | |
List<SmartFormField> smartFormFields = new List<SmartFormField>(); | |
// loop through all fields and convert them to "SmartFormField" objects | |
foreach (TXTextControl.DocumentServer.PDF.AcroForms.FormField field in formFields) { | |
switch (field) { | |
case FormTextField textField: | |
smartFormFields.Add(new SmartTextFormField() { | |
Name = textField.FieldName, | |
Text = textField.Value, | |
DisplayName = textField.AlternateFieldName | |
}); | |
break; | |
case TXTextControl.DocumentServer.PDF.AcroForms.FormCheckBox checkBoxField: | |
smartFormFields.Add(new SmartCheckboxField() { | |
Name = checkBoxField.FieldName, | |
Checked = checkBoxField.IsChecked, | |
DisplayName = checkBoxField.AlternateFieldName | |
}); | |
break; | |
case FormComboBox comboBoxField: | |
SmartDropdownField sddf = new SmartDropdownField() { | |
Name = comboBoxField.FieldName, | |
Text = comboBoxField.Value, | |
DisplayName = comboBoxField.AlternateFieldName | |
}; | |
foreach (var item in comboBoxField.Options) { | |
sddf.Items.Add(item); | |
} | |
smartFormFields.Add(sddf); | |
break; | |
} | |
} | |
// return fields | |
return smartFormFields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment