Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells APIs provide the facility to render spreadsheets in image formats as well as convert them to PDF and XPS formats. To maximize conversion fidelity, it is necessary that the fonts used in the spreadsheet are available in the operating system’s default font directory. If the required fonts are not present, Aspose.Cells APIs will attempt to substitute the required fonts with the ones available.
Below is the process that Aspose.Cells APIs follow behind the scenes:
Aspose.Cells APIs search the operating system’s default font directory for the required fonts. If the required fonts are not available in the system’s font directory, the APIs search through custom (user‑defined) directories. The FontConfigs class provides several ways to set custom font directories, as detailed below:
#include <iostream>
#include <fstream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
Vector<uint8_t> GetDataFromFile(const U16String& file)
{
std::string f = file.ToUtf8();
// open a file
std::ifstream fileStream(f, std::ios::binary);
if (!fileStream.is_open()) {
std::cerr << "Failed to open the file." << std::endl;
// Return an empty vector on error
return Vector<uint8_t>();
}
// Get file size
fileStream.seekg(0, std::ios::end);
std::streampos fileSize = fileStream.tellg();
fileStream.seekg(0, std::ios::beg);
// Read file contents into uint8_t array
uint8_t* buffer = new uint8_t[fileSize];
fileStream.read(reinterpret_cast<char*>(buffer), fileSize);
fileStream.close();
Vector<uint8_t> data(buffer, fileSize);
delete[] buffer;
return data;
}
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String fontFolder1 = srcDir + u"Arial";
U16String fontFolder2 = srcDir + u"Calibri";
U16String fontFile = srcDir + u"arial.ttf";
FontConfigs::SetFontFolder(fontFolder1, true);
Vector<U16String> fontFolders{ fontFolder1 , fontFolder2 };
FontConfigs::SetFontFolders(fontFolders, false);
FolderFontSource sourceFolder(fontFolder1, false);
FileFontSource sourceFile(fontFile);
Vector<uint8_t> fontData = GetDataFromFile(fontFile);
MemoryFontSource sourceMemory(fontData);
Vector<FontSourceBase> fontSources{ sourceFolder ,sourceFile ,sourceMemory };
FontConfigs::SetFontSources(fontSources);
Aspose::Cells::Cleanup();
}
Aspose.Cells APIs also provide the ability to specify substitute fonts for rendering purposes. This mechanism is helpful when a required font is not available on the machine where the conversion has to take place. Users can provide a list of font names as an alternative to the originally required font. To achieve this, the Aspose.Cells APIs have exposed the FontConfigs.SetFontSubstitutes method, which accepts two parameters. The first parameter is of type string, which should be the name of the font that needs to be substituted. The second parameter is an array of type string. Users can provide a list of font names as a substitution for the original font name (specified in the first parameter).
Here is a simple usage scenario:
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Substituting the Arial font with Times New Roman & Calibri
Vector<U16String> substituteFonts{ u"Times New Roman", u"Calibri" };
FontConfigs::SetFontSubstitutes(u"Arial", substituteFonts);
Aspose::Cells::Cleanup();
}
In addition to the above‑mentioned methods, the Aspose.Cells APIs also provide means to gather information on what sources and substitutions have been set:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.