Foxit Quick PDF Library

Extract fonts from a PDF programmatically

Foxit Quick PDF Library lets you extract embedded TrueType fonts from PDF files to a font file on the local disk. All other font types and subsetted TrueType fonts are not supported by the SaveFontToFile function. Here is some C# code that demonstrates how to extract the embedded fonts.

// Load the PDF
DPL.LoadFromFile("fonts.pdf", "");

// Iterate through all fonts found in the PDF
for (int i = 1; i < DPL.FindFonts(); i++)
{
// Get font ID for next font and select it
int FontID = DPL.GetFontID(i);
DPL.SelectFont(FontID);

// Check to see if font is TrueType embedded
if (DPL.FontType() == 4)
{
// Save font to disk
DPL.SaveFontToFile(DPL.FontName() + ".ttf");
}  
}

Some details:

  1. First you need to load the PDF using the LoadFromFile function or one of the other LoadFrom* functions.
  2. Then you need to count all of the fonts in the document using the FindFonts function. This function will return the total number of fonts in the document. Use this as an index to loop through each font in the document — starting from 1 to the total number of fonts.
  3. While looping through the index of the fonts, retrieve the fond ID and use this ID to select the font using the SelectFont function.
  4. Only embedded TrueType fonts are supported by the SaveFontToFile function, so you need to use the FontType function to filter our all fonts that are not embedded TrueType fonts.
  5. Finally, now you can save the embedded TrueType fonts to disk using the SaveFontToFile function as they are discovered in the loop.

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: