Spread.Sheets Documentation
Use Custom Font for PDF Export
Spread.Sheets Documentation > Developer's Guide > Managing Data > Exporting to PDF > Use Custom Font for PDF Export

The Export to PDF feature in Spread.Sheets allows users to embed both standard fonts and custom fonts. If users don't want to use the standard fonts while exporting to PDF, they can use the custom fonts.

When custom fonts are used, PDF is embedded as the subset of the font in the file. But users must embed the font file while performing the export operation.

In order to register a custom font for exporting PDF, you can use the registerFont method of the PDFFontManager class. You can also provide a custom font file for the specific font string by using the fallbackFont method of the PDFFontManager class.

Using Code

This example shows how to use the registerFont method to register a custom font.

JavaScript
Copy Code
var font = {
    normal: fonts['SIMSUN.ttf']
};
GC.Spread.Sheets.PDF.PDFFontsManager.registerFont('SimSun', font);

Using Code

This example shows how to use the fallbackFont method to provide a custom font file for the specific font string.

JavaScript
Copy Code
GC.Spread.Sheets.Print.PDFFontsManager.fallbackFont = function (font) {
    var fontInfoArray = font.split(' '), fontName = fontInfoArray[fontInfoArray.length - 1];
    if (fontName === 'Calibri') {
        return Calibri.ttf(encode with base64);
    }
    return Arial.ttf(in ArrayBuffer)
}

Note: While using custom font for PDF export, it is necessary to ensure that the font contains all the charsets that you have used. Not doing so can make your PDF file non-readable.