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

可能的使用场景

通常情况下,您可以为所有工作簿指定字体目录或字体列表,但有时需要为工作簿指定个别或私有字体集。Aspose.Cells 提供了IndividualFontConfigs类,可用于为工作簿指定个别或私有字体集。

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

以下示例代码加载了使用IndividualFontConfigs类指定的其个体或私有字体集的sample Excel file,请参阅代码中使用的sample font以及由它生成的output PDF。以下截图显示了如果成功找到字体,输出的PDF的外观。

todo:image_alt_text

示例代码

// 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);