0

I am using spire to generate a pdf document. All works well but now I want to change the font of one of the text fields to my own font. Any ideas how to do this? My code to generate pdf as as below

 using (PdfDocument doc = new PdfDocument())
 {
     doc.LoadFromFile(MyFileTemplate);
     PdfFormWidget formWidget = doc.Form as PdfFormWidget;

     (formWidget.FieldsWidget["UserID"] as PdfTextBoxFieldWidget).Text = Username;
     (formWidget.FieldsWidget["Name"] as PdfTextBoxFieldWidget).Text =Name;
     (formWidget.FieldsWidget["Address"] as PdfTextBoxFieldWidget).Text = Address;

     doc.SaveToFile(MyFilePath);
}

I tried using

PdfTrueTypeFont font = new PdfTrueTypeFont("My Font Name", 10f);
(formWidget.FieldsWidget["Address"] as PdfTextBoxFieldWidget).Text.Font = font;

But this dint work

user2837961
  • 1,505
  • 3
  • 27
  • 67

3 Answers3

0

Try this

PdfTrueTypeFont font = new PdfTrueTypeFont("My Font Name", 10f);
(formWidget.FieldsWidget["Address"] as PdfTextBoxFieldWidget).Font = font;

Please Mark as Answer if it solves the problem.Thank you.

Kumar
  • 17
  • 1
0

It seems that your method only works for the textbox created by the Adobe. If you draw the text using Spire.Pdf, please change the code as below:

PdfForm formWidget = doc.Form as PdfForm;
PdfTrueTypeFont font = new PdfTrueTypeFont("My Font Name", 10f);
(formWidget.Fields["Address"] as PdfTextBoxField).Font = font;
Jane.Bai
  • 16
  • 1
0

Now your code works well with the newest hotfix(Spire.pdf3.9.82), you can try it.

I'm an employee of e-iceblue.

Jane.Bai
  • 16
  • 1