Layout issue on axis labels in image rendered from Excel chart

Hi,

When rendering an Excel chart to an image, I noticed some axis labels became two lines and overlapped the legend.

Code:

var fileName = “axis line”;
var workbook = new Workbook(fileName + “.xlsx”);
var options = new ImageOrPrintOptions
{
ImageType = ImageType.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true,
Transparent = true
};

        workbook.Worksheets["sheet1"].Charts[0].ToImage(fileName + ".emf", options);

I’ve attached the test files and a screenshot for your reference. Could you please help me check this?

axis line.png (44.2 KB)
axis line.zip (14.8 KB)

Thanks,

@ServerSide527,

Thanks for the template file, sample code, screenshot and output image.

Please try our latest version/fix: Aspose.Cells for .NET v18.10.7:

Aspose.Cells18.10.7 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.10.7 For .Net4.0.Zip (4.7 MB)

If you still find the issue with v18.10.7, kindly do provide the underlying font files used in the workbook (e.g “Source Sans Pro”), we will check it soon.

Hi,

Thanks for the update. I have tried 18.10.7 but still no luck. Please find my attached SourceSansPro-Regular font.

SourceSansPro-Regular.zip (126.8 KB)

Thanks,

@ServerSide527,

Thanks for sharing the font file.

I did install the font on my pc (OS: Windows 8) but still the exception (“Font ‘Source Sans Pro’ does not support style ‘Regular’”) occurred. Even Ms Excel does not show the axis labels when opening the file into it, see the screenshot for your reference:

Could you change the font and re-save the file to provide us here to reproduce the issue on our end, we will check it soon.

Hi,

Thanks for your feedback. I’ve attached the test files with changed font ‘Calibri’ and was still able to reproduce the issue.

Please find my attachment.

axis line (2).zip (14.8 KB)

Meanwhile I have another post also using the same font in the attachment, would you like me to update that as well?

Thanks

@ServerSide527,

I tried your new file (I still have to remove the TextBox because it is using “Source Sans Pro” font) with your sample code using v18.10.7 and the output image is fine tuned. Please find it attached.

Let us know if you see any issue with the output image.
axis line.zip (4.1 KB)

Hi,

Thanks for your tests. I have taken a look and it seems it used an unlicensed version, I’m not sure if that would make a difference. Also even if the text was not wrapped into two lines, some labels are missing in your output:
image.png (4.4 KB)

Could you please check that?

Thanks,

@ServerSide527,

I am also using Aspose.Cells for .NET v18.10.7 without a license. Could you open my output image file if you see any issue in it.

@Amjad_Sahi

I mean the one I used was the licensed version and I don’t know if that was why it made a difference on your output.

The screenshot I took in my last reply was from your output, where the labels are still incorrect. Could you check that?

@ServerSide527,

I used a valid license now (to be set in the code at the start) and tried the code segment with v18.10.7 to produce the output image, the output image is again fine tuned. Please find it attached too. Also, see the screenshot when I opened the output image into MS Paint, you can see the x-axis labels are ok.

Moreover, I saved your template file to PDF and now I found those labels are in two lines. So, I find the issue only when I save your template file to PDF file format. But using your sample code (Chart to image feature) to render to image for the chart does not reproduce the issue. Do you want me to log a ticket for Excel to PDF rendering? We can log a ticket for it on your confirmation.
axis line_new1.zip (3.6 KB)

Hi,

Many thanks for the investigation. It is still weird that when I opened your attachment using paint, the text on ‘Mar’ is still missing, while clearly in your pc the image is looking ok. (I’ve attached a gif for you)
record.zip (273.5 KB)

There’s also one thing I found very weird on this image: if I drag and drop this image to a Word document, and saved to pdf using Word ‘save as’. It throws an error:
image.png (13.9 KB)

I’ve attached the docx with your image for your reference. You can try saving it to pdf using Office and see the result. Maybe it is also related?
cannotsavedtopdf.zip (13.1 KB)

And thanks for observing the issue in pdf, as it could be related, could we log a ticket on this first?

Thanks

@ServerSide527,

That is strange. Could you try your scenario on some other machines with different OS and let us know your feedback. Also provide details about your environment (OS, CPU, display settings, .NET Framework versions, etc.) where you find this issue, we will log the details.

I am able to reproduce the issue as per your description and details. May be this issue is relevant to your original issue. I have logged a ticket with an id “CELLSNET-46451” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Hi, @Amjad_Sahi

Many thanks for your information and the ticket related to the issue on pdf.

Regarding the image difference, as you suggested I have tried using different machines to open your emf, and here are my findings

Machine 1: Windows 7 SP1 64bit, gdi32.dll version 6.1.7601.24260, GdiPlus.dll version 6.1.7601.24234, the highest .net framework is 4.7.1, the text is missing
Machine 2: Windows 10 64bit, gdi32.dll version 6.2, GdiPlus.dll version 6.2, the highest .net framework is 4.7.1, the text is not missing
Machine 3: Windows Server 2012, gdi32.dll version 6.3, GdiPlus.dll version 6.3, the text is not missing.

Could it be the version of the gdi32, gdi+ installed on the OS that made the graphic difference? Does Aspose have any known limitation on the gdi+ versions? Which gdi32.dll and GdiPlus.dll version are you using?

Thanks,

@ServerSide527,

Thanks for sharing details about your environments and findings.

It looks like issue occurs on the machines with gdi32 and gdi+ libraries having version < 6.2. I have logged your details and findings against your issue into our database. We will investigate and look into your issue soon.

Once we have an update on it, we will let you know.

@ServerSide527,

We don’t know why your machine does not display the text. We use Metafile(Stream, IntPtr, Rectangle, MetafileFrameUnit, EmfType) method to create emf image and specify EmfType.EmfPlusDual. EmfPlusDual means that all EMF+ records in the metafile are associated with an alternative EMF record. Metafiles of type EmfPlusDual can be displayed by GDI or by GDI+. We will try to fix the issues and provide a new hot-fix this weekend.

Keep in touch.

@ServerSide527,

Please try our latest version/fix: Aspose.Cells for .NET v18.11.6 (attached)

Your issue should be fixed in it.

Let us know your feedback.
Aspose.Cells18.11.6 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.11.6 For .Net4.0.Zip (4.7 MB)

The issues you have found earlier (filed as CELLSNET-46451) have been fixed in Aspose.Cells for .NET v18.12. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi

Thanks for the update.

I have tested the scenario using the latest Aspose.Cells but found the two issues we discovered in this thread still exist:

I tried to save the worksheet to pdf and found the layout in pdf is still incorrct:
axis lineNew.zip (36.8 KB)
image.png (23.7 KB)

I also tried to insert the output image to a Word document and used ‘Save As’ to save to pdf. And it still showed the error:
image.png (2.4 KB)
wordsaveaserror.zip (104.9 KB)

Could you please help me check?

Thanks,

@ServerSide527,

Thanks for the template files, screenshots and details.

  1. As we already reproduced the issue for Excel to PDF rendering where some labels are in two lines in the output PDF file format, so we have logged a ticket with an id “CELLSNET-46518” for your issue. We will look into it soon.

  2. I did reproduce the issue. I can find the error as per the screenshot (https://forum.aspose.com/uploads/default/22194 - prompted by MS Word) when I manually save the file (after inserting output image (by Aspose.Cells APIs) for the chart into a Word document) to PDF file format. I have reopened the issue “CELLSNET-46451”. We will look into it soon.

Once we have an update on any of the issues, we will let you know.

@ServerSide527,

Please try our latest version/fix: Aspose.Cells for .NET v18.12.5 (attached)

  1. Please try the fix. As the category axis labels are just to be laid to one line, it means they are in a critical state. When you reduce the chart in MS Excel manually, you will also find the change in the layout. I am afraid, now we might not mimic exactly the same as MS Excel for all scenarios/cases.

  2. Please try the fix. We added a property named EmfType for ImageOrPrintOptions. Please save the chart to emf image with ImageOrPrintOptions.EmfType = EmfType.EmfOnly. We don’t know why MS Word cannot save the generated emf to PDF file format. We create the emf format image using Metafile(Stream, IntPtr, Rectangle, MetafileFrameUnit, EmfType) method. In our previous version, EmfType is EmfPlusDual. In this fix, we open the argument. You can set it to EmfOnly.

Let us know your feedback.
Aspose.Cells18.12.5 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.12.5 For .Net4.0.Zip (4.7 MB)