You can populate fields of a WorkflowGen web form (built with the Form Designer) with values from a PDF form uploaded by the current user. To do this:
-
Reference the PDFSharp component (open source). Download PDFSharp and copy the DLLs into the
\wfgen \WfApps\WebForms\Bin\PDFSharp.dll
folder. -
Insert an attachment tool in your web form. From the toolbar, select the Attachment tool and click on
+
to insert it into your selected section. -
Edit your inserted attachment by clicking on the pencil icon.
-
On the Behavior tab, check
WorkflowFileUpload
and set PDF for only allowed extensions. -
On the Custom Attributes tab, add the attribute
Name: ononfileuploaded, Value: OnFileUploaded
.
-
-
Add code-behind in your web form. In the Form Designer, click on the .NET icon.
-
Add and customize with your fields’ IDs the following code:
protected void OnFileUploaded(object sender, UploadedFileEventArgs e){ string value = null; // DropDownlist (Radiobuttonlist, checkboxlist) value = GetFieldValue(e.File.FullName, "PDF_MYDROPDOWNLIST"); if (!String.IsNullOrEmpty(value)) { this.REQUEST_DROPDOWNLIST1.SelectedValue = value; } // Textbox (textarea) this.REQUEST_COMMENT.Text = GetFieldValue(e.File.FullName, "PDF_TEXT");} protected string GetFieldValue(string PdfTemplatePath, string FieldName){ string value = null; PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(PdfTemplatePath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.ReadOnly); // Get the root object of all interactive form fields PdfSharp.Pdf.AcroForms.PdfAcroForm form = document.AcroForm; // Get all form fields of the whole document PdfSharp.Pdf.AcroForms.PdfAcroField.PdfAcroFieldCollection fields = form.Fields; // Get the field PdfSharp.Pdf.AcroForms.PdfAcroField field = fields[FieldName]; if (field != null) { PdfSharp.Pdf.AcroForms.PdfTextField txtField; PdfSharp.Pdf.AcroForms.PdfRadioButtonField radField; PdfSharp.Pdf.AcroForms.PdfCheckBoxField chkField; PdfSharp.Pdf.AcroForms.PdfListBoxField lbxField; PdfSharp.Pdf.AcroForms.PdfComboBoxField cbxField; PdfSharp.Pdf.AcroForms.PdfGenericField genField; if ((txtField = field as PdfSharp.Pdf.AcroForms.PdfTextField) != null) { value = txtField.Text; } else if ((radField = field as PdfSharp.Pdf.AcroForms.PdfRadioButtonField) != null) { value = Convert.ToString(radField.Value); } else if ((chkField = field as PdfSharp.Pdf.AcroForms.PdfCheckBoxField) != null) { value = Convert.ToString(chkField.Value); } else if ((lbxField = field as PdfSharp.Pdf.AcroForms.PdfListBoxField) != null) { value = Convert.ToString(lbxField.Value); } else if ((cbxField = field as PdfSharp.Pdf.AcroForms.PdfComboBoxField) != null) { value = Convert.ToString(cbxField.Value); } else if ((genField = field as PdfSharp.Pdf.AcroForms.PdfGenericField) != null) { value = Convert.ToString(genField.Value); } } if (value.StartsWith("/")) { value = value.Remove(0, 1); } return value;}