Skip to content

Font Management

The ComPDFKit PDF SDK supports reading the font families and their styles available on your device, and setting them as fonts for various functionalities such as annotations, forms, watermarks, headers, footers, Bates numbering, and more. This will assist you in designing aesthetically pleasing PDF files or adjusting and enhancing your PDF files with fonts that comply with certain specifications.

When setting fonts using font management, you need to:

  1. Retrieve the names of all font families in the system.
  2. Select the font you need and obtain the style names for the font family.
  3. After selecting the style name, obtain the PostScript name of the font based on the font family name and style name.
  4. The PostScript name can then be used to set the font.

This example shows how to use font management:

C#
int familyNameIndex = 0;
int styleNameIndex = 0;

// Get the list of font families and choose a font family
List<string> fontFamilyNames = CPDFFont.GetFontNameDictionary().Keys.ToList();
string fontFamilyName = fontFamilyNames[familyNameIndex];

// Get the list of font styles corresponding to the font family and choose a font style
List<string> fontStyleNames = CPDFFont.GetFontNameDictionary()[fontFamilyName];
string fontStyleName = fontStyleNames[styleNameIndex];

// Get the PostScript name based on the font family and font style
string postScriptName = string.Empty;
CPDFFont.GetPostScriptName(fontFamilyName, fontStyleName, ref postScriptName);

// Apply the PostScript name to the functionality that requires font setting. 
// For specific attribute settings, refer to the documentation of the corresponding functionality.
CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
watermark.SetFontName(postScriptName);

About Font Family and Style Names

  1. Font Family:

    Font Family refers to the group or series name of a font, typically representing a set of fonts that share a common design style.

    For example, the Helvetica font family includes various styles such as Helvetica Regular, Helvetica Bold, and Helvetica Italic, all of which belong to the Helvetica font family.

  2. Font Style:

    Font Style refers to the specific style or variant name of a font. It is commonly used to differentiate between different font styles within the same font family, such as bold, italic, regular, etc.

    Taking the Helvetica font family as an example, Regular, Bold, Italic, etc., are all different style names.