I have an issue when rendering a worksheet range to an EMF image when the font is from Aptos family.
The render creates an image where the text lacks spaces as seen in this screenshot: image.png (739 Octets)
When copied in PPT, it looks like this: image.png (2,4 Ko)
Source data in Excel looks like this: image.png (2,1 Ko)
I am aware of the need to select the font folder, as describes in this other support thread: Default Excel font Aptos not printed.
But even with the addition of such line, the result remains unchanged.
There is my code to generate the image:
public static void ExportToImage(string sourceDocument, string worksheetName, string destinationFile, string rangeAddress)
{
Console.WriteLine(@"Aptos Narrow is available: " + FontConfigs.IsFontAvailable("Aptos Narrow")); // returns true
string winFontCacheFolder =
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "FontCache");
FontConfigs.SetFontFolder(winFontCacheFolder, true);
Console.WriteLine(@"Aptos Narrow is available: " + FontConfigs.IsFontAvailable("Aptos Narrow")); // returns true
Workbook asposeWorkbook = new Workbook(sourceDocument);
var asposeSheet = asposeWorkbook.Worksheets[worksheetName];
var range = asposeSheet.Cells.CreateRange(rangeAddress);
ImageOrPrintOptions options = new ImageOrPrintOptions()
{
ImageType = ImageType.Emf,
OnlyArea = true,
Transparent = true,
DefaultFont = "Arial"
};
asposeSheet.PageSetup.PrintArea = range.RefersTo;
asposeSheet.PageSetup.CustomPaperSize(MeasureUnitsHelper.PointToInch(range.Width), MeasureUnitsHelper.PointToInch(range.Height));
var renderer = new SheetRender(asposeSheet, options);
renderer.ToImage(0, destinationFile);
}
Is there something missing in my code to render properly the image?
It seems you’re experiencing issues with rendering text from the Aptos font family in an EMF image. The problem of missing spaces in the rendered text could be related to how the font is being handled during the rendering process.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
Ensure Font Availability: Confirm that the Aptos Narrow font is correctly installed on your system and accessible to the application. You can check this using the FontConfigs.IsFontAvailable("Aptos Narrow") method.
Set the Font Folder: You are correctly setting the font folder to the Windows Font Cache. Ensure that the path is accurate and that the application has permission to access it. The following code snippet demonstrates how to set the font folder:
Remove Default Font Setting: In your ImageOrPrintOptions, you have set DefaultFont to “Arial”. If the Aptos font is not rendering correctly, consider removing this line entirely, as it may lead to unintended font substitutions.
Check for Font Substitution: If the rendering engine does not fully support the Aptos font, it may substitute it with a different font, which can lead to issues like missing spaces. Ensure that the Aptos font is fully supported by the rendering engine you are using.
Update Aspose.Cells: Ensure you are using the latest version of Aspose.Cells, as updates may include fixes for rendering issues.
Test with Different Formats: If the issue persists, consider exporting the range to a different image format (like PNG or JPEG) to determine if the problem is specific to EMF.
Here’s a modified version of your code snippet that removes the DefaultFont setting:
public static void ExportToImage(string sourceDocument, string worksheetName, string destinationFile, string rangeAddress)
{
Console.WriteLine(@"Aptos Narrow is available: " + FontConfigs.IsFontAvailable("Aptos Narrow")); // returns true
string winFontCacheFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "FontCache");
FontConfigs.SetFontFolder(winFontCacheFolder, true);
Console.WriteLine(@"Aptos Narrow is available: " + FontConfigs.IsFontAvailable("Aptos Narrow")); // returns true
Workbook asposeWorkbook = new Workbook(sourceDocument);
var asposeSheet = asposeWorkbook.Worksheets[worksheetName];
var range = asposeSheet.Cells.CreateRange(rangeAddress);
ImageOrPrintOptions options = new ImageOrPrintOptions()
{
ImageType = ImageType.Emf,
OnlyArea = true,
Transparent = true
};
asposeSheet.PageSetup.PrintArea = range.RefersTo;
asposeSheet.PageSetup.CustomPaperSize(MeasureUnitsHelper.PointToInch(range.Width), MeasureUnitsHelper.PointToInch(range.Height));
var renderer = new SheetRender(asposeSheet, options);
renderer.ToImage(0, destinationFile);
}
Try these suggestions and see if they help resolve the rendering issue. If the problem persists, consider reaching out to Aspose support for further assistance.
After initial testing, I am able to reproduce the issue as you mentioned by using your template Excel file and sample code snippet. I found incorrect rendering of text (for A1:B2 range) with font from Aptos family.
We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-59244
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.