Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
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 |
|---|
![]() |
Aspose.Cells will substitute the fonts in cells A6 and A7 with suitable fonts, as shown below.
| Substituted fonts |
|---|
![]() |
You can download the source Excel file and the output PDF from the following links
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);
}
}
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 ].
Workbook.calculateFormula() method just before rendering the spreadsheet to PDF format. Doing so will ensure that the formula‑dependent values are recalculated and the correct values are rendered in the PDF.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.