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.
The Emf image is the vector image. It relies on the installed font when you open it in Image viewer.
The Aptos fonts(e.g. “Aptos Narrow”) are cloud fonts which are not installed on the System actually.
After you installing the Aptos fonts into System, reopen the image(Please close all Excel/PPT instances firstly, if you view the image in Excel/PPT), it will be OK.
Thanks for the answer. Indeed, after installing the fonts from the cache folder (C:\Users[my name]\AppData\Local\Microsoft\FontCache\4\CloudFonts\Aptos Narrow) the images created are good.
However, without using Aspose, when I copy/paste a range from Excel to PowerPoint using Paste Special/Picture (Enhanced Metafile), the image created does not require the font to be installed on the computer.
This zip file contains two EMF files, based on the same range in Excel, with font = “Aptos Display” : Aptos Display comparison.zip (3,3 Ko)
You can see that the EMF file generated by Office is as expected, while the one generated by Aspose.Cells fails to render the font.
When analyzing the EMF file, I can see that there is no mention at all of “Aptos” on the file generated by Aspose.Cells while “Aptos Display” font is well mentioned in the file generated by Office.
For record, as I am not familiar with the EMF format, I used a small EMF analyzer project found online to decode both files. You may find it here : Parse, understand and demystify Enhanced Meta Files (EMF) with C# - CodeProject
It seems a bug to me, where Aspose.Cells requires the font to be installed on the computer in order to generate the proper image instead of also looking for the font cloud cache folders (which I set with
FontConfigs.SetFontFolder(winFontCacheFolder, true); in the code sample I shared above). Or I am missing something.
@Gradlon
Thank you for your feedback. I’m glad you solved the issue by installing fonts in the cache folder. We will further investigate the cloud caching font you mentioned. We will notify you promptly once there are any updates.
To be honest, on my side, I can’t consider the issue solved, because it is quite complicated to explain to my customers that they must install the fonts from the cache. Especially for the Aptos family which is the default font on Windows now.
@Gradlon
Thank you for your feedback. We have reopened the ticket CELLSNET-59244. As a temporary solution, you can first solve the issue by installing fonts in the cache folder. Regarding cloud cached fonts, we will notify you promptly if there are any updates.
Please make sure that “Aptos Display” fonts are aldready cached in your folder C:\Users\[my name]\AppData\Local\Microsoft\FontCache before converting to Emf by Aspose.Cells. The “Aptos Display” will be used in the generated Emf image.
For the issue that the text lacks sapces, we will investigate further the Excel (copy/paste) generated Emf image and our generated Emf image.
In your shared Emf images, the font “Aptos Display” is not used in the aspose generatd Emf image. Since the font is in your cached folder, you may try it again to use aspose to convert to Emf image, the “Aptos Display” font should be used.
We will thoroughly investigate the issue regarding the spaces. Additionally, we will evaluate and compare the EMF image generated through Excel (copy/paste) with the one generated by us. We will update you with our findings soon.