Skip to content
English
  • There are no suggestions because the search field is empty.

[Public] Using Custom Fonts in Form Fields with IronPDF

A practical workaround for the current SetFont() limitation

IronPDF is a powerful .NET library that enables developers to generate, manipulate, and edit PDF documents with ease. One of its capabilities includes working with interactive form fields. However, there is a known limitation with the SetFont() method when customizing fonts and styles in form fields—specifically, users are currently unable to apply custom fonts directly using this method.

Despite this limitation, there is an effective workaround using the DefaultAppearance property of a form field. This property accepts a string representing PDF drawing instructions to control font styling and color. By manually constructing this string, users can still style form field text using fonts available on their system.

Workaround Example: Styling a Form Field with Custom Font and Color

Below is a sample code snippet demonstrating how to style a form field using the DefaultAppearance property:

var pdf = PdfDocument.FromFile("FilledForm.pdf");

TextFormField field = pdf.Form[0] as TextFormField;

// Manually define the appearance string:
// Format: /{FontName}-{Weight} {FontSize} Tf {R} {G} {B} rg
field.DefaultAppearance = "/AdobeThai-Bold 15 Tf 0.898 0.133 0.215 rg";

field.Value = "This is size 15";

pdf.SaveAs("customformfieldvalue15.pdf");

 

Explanation of Parameters

  • /AdobeThai-Bold: The font name and weight. This must be installed on the system.

  • 15 Tf: Font size (15 pt).

  • 0.898 0.133 0.215 rg: RGB color values (in this case, a reddish shade).

This workaround allows developers to retain full control over the font and style used in form fields until official support via SetFont() is available in a future IronPDF release.