为工作簿呈现指定单个或私有字体集

可能的使用场景

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

为工作簿呈现指定单个或私有字体集

下面的示例代码加载示例 Excel 文件及其使用指定的单独或私有字体集个人字体配置班级。请参阅样本字体在代码中使用以及输出 PDF由它产生。以下屏幕截图显示了如果成功找到字体,输出 PDF 的外观。

待办事项:图片_替代_文本

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// 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.setFontConfigs(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);