i am trying to populate a PDF using field names in PDF which i am able to do, however i want to change the font how can i do this
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;
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontPath, fontSize); //not sure what to do from here
//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();
}
when i try to do this
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontPath, fontSize);
and do
if (textField.Name == f.Key)
{
textField.Font = trueTypeFont;
textField.Text = f.Value;
}
my program fails can someone help me figure a way out of this please.