Change Font in a PDF Form
Any PDF document supports a set of standard 14 fonts. They are available in most PDF viewers and ensure consistent document representation on any device. The standard 14 fonts include the following fonts and their variants:
- Helvetica | Helvetica-Bold | Helvetica-BoldOblique | Helvetica-Oblique
- Courier | Courier-Bold | Courier-BoldOblique | Courier-Oblique
- Times-Roman | Times-Bold | Times-Italic | Times-BoldItalic
- Symbol
- ZapfDingbats
SurveyJS PDF Generator supports these fonts out of the box. To apply one of them, specify the fontName
property in the IDocOptions
object.
You can also use custom fonts in your PDF document. Unlike the standard fonts, custom fonts are embedded in the document and increase its size. To add a custom font, call the DocController.addFont(fontName, base64, fontStyle)
method with the following parameters:
fontName
:string
A custom name that you will use to apply a custom font.base64
:string
The custom font as a Base64-encoded string. To encode your font to Base64, obtain it as a TTF file and use any TTF-to-Base64 online converter.fontStyle
:"normal"
|"bold"
|"italic"
|"bolditalic"
The style of the custom font.
To apply a custom font to a PDF document, assign its name to the fontName
property in the IDocOptions
object. This setting applies a custom font to all survey questions except HTML. To include HTML questions too, enable the useCustomFontInHtml
property. This demo applies the Roboto font to a PDF document that contains HTML questions among others.