Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 7, 2023 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/7b3f809c9aecbec449d85ee142ffad6b to your computer and use it in GitHub Desktop.
Save bjoerntx/7b3f809c9aecbec449d85ee142ffad6b to your computer and use it in GitHub Desktop.
[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