the code i am using to populate data and to output them is below, please if some one can provide guidance on how to do this.
- Code: Select all
public void FillPdf(string pdfTemplatePath, string outputPdfPath, Dictionary<string, string> fieldData, string fontPath, float fontSize)
{
Logger logger = new Logger(logFilePath);
PdfDocument document = new PdfDocument(pdfTemplatePath);
PdfFormWidget loadedForm = document.Form as PdfFormWidget;
//Go through the forms
for (int i = 0; i < loadedForm.FieldsWidget.List.Count; i++)
{
PdfField field = loadedForm.FieldsWidget.List[i] as PdfField;
//Fill textbox form field
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textField = field as PdfTextBoxFieldWidget;
//Get the field name and fill with content
foreach(var f in fieldData)
{
if (textField.Name == f.Key)
{
textField.Text = f.Value;
}
}
}
}
loadedForm.FieldsWidget.FormWidget.ReadOnly = true;
//Save and close
document.SaveToFile(outputPdfPath,FileFormat.PDF);
document.Close();
}