Specify Individual or Private Set of Fonts for Workbook Rendering with C++
Possible Usage Scenarios
Generally, you specify the fonts directory or list of fonts for all workbooks, but sometimes, you have to specify individual or private set of fonts for your workbooks. Aspose.Cells provides the IndividualFontConfigs class that can be used to specify the individual or private set of fonts for your workbook.
Specify Individual or Private Set of Fonts for Workbook Rendering
The following sample code loads the sample Excel file with its individual or private set of fonts, which are specified using the IndividualFontConfigs class. Please see the sample font used inside the code as well as the output PDF generated by it. The following screenshot shows how the output PDF looks if the font is found successfully.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Path of your custom font directory
U16String customFontsDir(u"C:\\TempDir\\CustomFonts");
// Specify individual font configs custom font directory
IndividualFontConfigs fontConfigs;
// 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(LoadFormat::Xlsx);
opts.SetFontConfigs(fontConfigs);
// Load the sample Excel file with individual font configs
Workbook wb(u"sampleSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.xlsx", opts);
// Save to PDF format
wb.Save(u"outputSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.pdf", SaveFormat::Pdf);
std::cout << "Workbook saved to PDF with custom font configurations successfully!" << std::endl;
Aspose::Cells::Cleanup();
}