指定工作簿渲染的个体或私有字体集

可能的使用场景

通常,您可以为所有工作簿指定字体目录或字体列表,但有时,您必须为您的工作簿指定单独或专用的字体集。 Aspose.Cells 提供了一个 IndividualFontConfigs 类,可用于为您的工作簿指定单独或专用的字体集。

指定工作簿渲染的个体或私有字体集

以下示例代码使用 IndividualFontConfigs 类指定了样本 Excel 文件及其单独或专用的字体集。 请在代码中查看所使用的样本字体以及由此生成的输出 PDF。 以下屏幕截图显示了如果成功找到字体时输出 PDF 的外观。

todo:image_alt_text

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Path of your custom font directory.
string customFontsDir = "C:\\TempDir\\CustomFonts";
// Specify individual font configs custom font directory.
IndividualFontConfigs fontConfigs = new IndividualFontConfigs();
// If you comment this line or if custom font directory is wrong or
// if it does not contain required font then output pdf will not be rendered correctly.
fontConfigs.SetFontFolder(customFontsDir, false);
// Specify load options with font configs.
LoadOptions opts = new LoadOptions(LoadFormat.Xlsx);
opts.FontConfigs = fontConfigs;
// Load the sample Excel file with individual font configs.
Workbook wb = new Workbook("sampleSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.xlsx", opts);
// Save to PDF format.
wb.Save("outputSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.pdf", SaveFormat.Pdf);