Get Warnings for Font Substitution while Rendering Excel File with Node.js via C++

To get warnings for font substitution when rendering Excel files to PDF, implement the IWarningCallback interface and set the PdfSaveOptions.warningCallback property with your implemented interface.

The screenshot below shows a source Excel file that we will use in the following code. It contains some text in cells A6 and A7 using fonts that are not rendered correctly by Microsoft Excel.

Not all fonts are rendered correctly
todo:image_alt_text

Aspose.Cells will substitute the fonts in cells A6 and A7 with suitable fonts, as shown below.

Substituted fonts
todo:image_alt_text

Download Source File and Output PDF

You can download the source Excel file and the output PDF from the following links

Code

The following code implements the IWarningCallback and sets the PdfSaveOptions.warningCallback property with the implemented interface. Now, whenever a font is substituted in any cell, Aspose.Cells will fire a warning via the WarningCallback.Warning() method.

const AsposeCells = require("aspose.cells.node");
const path = require("path");

class GetWarningsForFontSubstitution {
    static warning(info) {
        if (info.getType() === AsposeCells.WarningType.FontSubstitution) {
            console.log("WARNING INFO: " + info.getDescription());
        }
    }

    static run() {
        // The path to the documents directory.
        const dataDir = path.join(__dirname, "data");
        const filePath = path.join(dataDir, "source.xlsx");
        const workbook = new AsposeCells.Workbook(filePath);

        const options = new AsposeCells.PdfSaveOptions();
        options.setWarningCallback(GetWarningsForFontSubstitution);
        const outputFilePath = path.join(dataDir, "output_out.pdf");
        workbook.save(outputFilePath, options);
    }
}

Output

After converting the source Excel file to PDF, the warnings are output to the debug console like this:

  

WARNING INFO: Font substitution: Font [ Athene Logos; Regular ] has been substituted in Cell [ A6 ] in Sheet [ Sheet1 ].  

WARNING INFO: Font substitution: Font [ B Traffic; Regular ] has been substituted in Cell [ A7 ] in Sheet [ Sheet1 ].