Hi,
This one is quite a weird and complex one and difficult to replicate but causes massive problems.
Aspose being server-side compatible we run it inside a service; in Windows this gives the process session 0. Here is a quick article explaining sessions in Windows:
https://blogs.technet.microsoft.com/askperf/2007/07/24/sessions-desktops-and-windows-stations/
However, on a certain hardware Aspose.Cells renderer behaves differently when run in session 0 as opposed to session 1. This causes the output image in different size in session 0 and session 1.
To test, you can use the following code:
var book = new Workbook(“Test.xlsx”);
Worksheet sheet = book.Worksheets[0];
sheet.PageSetup.PrintArea = “A1:B2”;
sheet.PageSetup.LeftMargin =
sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Png,
OnlyArea = false,
OnePagePerSheet = true,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit
};
new SheetRender(sheet, options).ToImage(0, “out.png”);
In session 1: The size of “out.png” is 194194.
In session 0: The size of “out.png” is 200194.
I had tried to set DPI in rendering options or in CellHelper.DPI, and had also tried to use different image format but the results were still different, and the difference was more significant if rendering it in .EMF format.
To run the program in session 0 you can use the following command as administrator to open up a session 0 session
psexec.exe -s -i 0 cmd.exe
Now the caveat here is that not all hardware we run it on produces the incorrect result. The problem only occurs on a specific hardware configuration. It is reproducible each time but only on that specific hardware (on all machines with that hardware configuration).
So it would be nice if you could check with engineers what the probable cause of this could be.
Best regards,
Hi John,
Hi Babar,
Thanks for your reply.
I’ve attached the exported hardware and OS/Locale information of my PC.
I’m using .NET Framework 4.5.1 and I’ve tested from Aspose.Cells 8.6.0 to 8.8.2 and all of them had this issue. (I didn’t test with older versions but I guess they may also have)
I also tested with other machines which have different Hardware but with the same software environment and the issue didn’t happen.
One thing might be helpful for your investigation is that the dpi (Image.HorizontalResoluton/Image.VerticalResolution) of output images in Session 1 and Session 0 are different (for .EMF images in session 1 it is 72.03544 while in session 0 it is 81.27999).
Another thing which might be important is that this issue only happens with SheetRender.ToImage(). When using Chart.ToImage() to render a single chart, the size and dpi of the output image in two sessions are exactly the same (for .emf chart images the dpi are both 95.97222).
I hope this information would be of any help for your investigation.
Thanks very much,
Hi John,
- We have recently addressed a problem related to the EMF rendering using SheetRender class so we need to make sure if this problem has been resolved or still reproducible with current latest revision of the API. Could you please re-execute your tests against the latest version of Aspose.Cells for .NET 8.8.2.8 (compiled against .NET Framework 4.0) and share the resultant PNG & EMF files generated from session 0 & 1?
- As you have mentioned that you have tried setting the DPI value in past but the problem was not resolved. Please note, you need to set the CellsHelper.DPI property at the start of your application, that is; before invoking any other objects from Aspose.Cells for .NET library. Could you please try setting the DPI value against Aspose.Cells for .NET 8.8.2.8 and share the results? The code will look as follow.
//Set License
var book = new Workbook(dir + “Test.xlsx”);
Worksheet sheet = book.Worksheets[0];
sheet.PageSetup.PrintArea = “A1:B2”;
sheet.PageSetup.LeftMargin =
sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Png,
OnlyArea = false,
OnePagePerSheet = true,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit
};
new SheetRender(sheet, options).ToImage(0, “out.png”);
options.ImageFormat = ImageFormat.Emf;
new SheetRender(sheet, options).ToImage(0, “out.emf”);
Hi Babar,
Thanks for providing the code and .dll file for testing.
I’ve attached the test results using “session 0 vs session 1” and also “setting DPI vs without setting DPI” with 8.8.2.8.
I could see setting DPI in advance will make the .png file look the same. While it made the .emf image trimmed (You can see output is trimmed in “outSession0CellHelperDPI96.emf”, some text is missing).
And when inserting “outSession1CellHelperDPI96.emf” and “outSession0CellHelperDPI96.emf” into Word, you will find the size is still different (session 1 is 6.846.88cm and session 0 is 6.066.09cm) even with setting DPI.
As for what I mentioned “setting the DPI value in past but the problem was not resolved”, actually I remember I met the same issue with .emf output when setting DPI to 96 using Aspose.Cells 8.6.3 and above, so I believe the trim does not only happen in this 8.8.2.8 version.
Also without setting DPI, the size of images including .emf and .png remain different, files are also provided in the attachments.
I hope that these test results help. As this issue is important to me, please let me know if you need more test results from my side.
Thanks,
Hi again,
Hi John,
sb.AppendLine("Version: " + CellsHelper.GetVersion());
sb.AppendLine("DPI: " + CellsHelper.DPI);
var book = new Workbook(“Test.xlsx”);
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
sb.AppendLine("Column A width in pixel: " + cells.GetColumnWidthPixel(0));
sb.AppendLine("Column B width in pixel: " + cells.GetColumnWidthPixel(1));
sb.AppendLine("Column A width in inch: " + cells.GetColumnWidthInch(0));
sb.AppendLine("Column B width in inch: " + cells.GetColumnWidthInch(1));
sb.AppendLine(“Row 1 height in pixel:” + cells.GetRowHeightPixel(0));
sb.AppendLine(“Row 2 height in pixel:” + cells.GetRowHeightPixel(1));
sb.AppendLine(“Row 1 height in inch:” + cells.GetRowHeightInch(0));
sb.AppendLine(“Row 2 height in inch:” + cells.GetRowHeightInch(1));
sheet.PageSetup.PrintArea = “A1:B2”;
sheet.PageSetup.LeftMargin =
sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Png,
OnlyArea = false,
OnePagePerSheet = true,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit
};
SheetRender sr = new SheetRender(sheet, options);
sb.AppendLine("Page size in pixel: " + sr.GetPageSize(0));
sr.ToImage(0, dir + “out.png”);
sb.Clear();
Hi Babar,
Thanks for your update.
I’ve attached the test results using Aspose.Cells 8.8.2.8.
As you requested, I tested it without setting DPI in advance in both session 1 and session 0.
Moreover, I’ve also attached the log results of pre-set DPI in advance in session 0 and also provided you all the .emf outputs for your reference. (You can see after presetting DPI, log.txt in session 0 are all the same as log.txt in session 1. But the .emf output is different (trimmed))
Thanks,
Hi again,
{
using (Graphics g = Graphics.FromImage(b))
{
Console.WriteLine("DPIX: " + g.DpiX);
Console.WriteLine("DPIY: " + g.DpiY);
}
}
Hi,
I’ve attached the results.
Thanks,
Hi,
Hi again,
Hi John,
The issues you have found earlier (filed as CELLSNET-44531) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
Thanks very much for the updates.
I’ve checked it and found it indeed made the size of the image outputs exactly the same between sessions and the trim of sheet .emf was resolved.
But I noticed another two new issues.
The first issue is that CellsHelper.DPI can only be set once. Any further modification on CellsHelper.DPI does not work after accessing the property.
Sample code:
Console.WriteLine(CellsHelper.DPI);
CellsHelper.DPI = 120;
Console.WriteLine(CellsHelper.DPI);
“CellsHelper.DPI = 120” doesn’t work because CellsHelper.DPI was read before.
Or:
CellsHelper.DPI = 120;
Console.WriteLine(CellsHelper.DPI);
CellsHelper.DPI = 96;
Console.WriteLine(CellsHelper.DPI);
“CellsHelper.DPI = 96” doesn’t work because CellsHelper.DPI was modified before.
The second thing is the chart image in session 0 looks wrong after setting the DPI .
Code:
CellsHelper.DPI = 96;
var book = new Workbook(@“test.xlsx”);
Worksheet sheet = book.Worksheets[0];
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
OnePagePerSheet = true
};
sheet.Charts[0].ToImage(@“out.Emf”, options);
There is significant difference between the out image and the original chart in session 0 (in the machine where session 0 has 120 DPI). While the tables are fine (but tables are rendered by SheetRender).
I’ve attached the output image in session 0 and session 1 for your reference.
Thanks,
Hi John,
Hi Babar,
Thanks for your reply.
Yes normally we shouldn’t need to reset DPI, it was only because the chart image works better with DPI value 120 in my session 0 (where the DPI is 120 by default). So I was thinking of rendering sheet by 96 DPI and when rendering charts I change the value back to 120. As long as chart image using 96 is correct, I will not need to reset DPI.
I tested with Aspose.Cells 8.8.3.2 you provided, and attached the results.
I found the labels were no longer overlapped that much in 8.8.3.2 when setting DPI to 96 in session 0, but the second line of labels were missing and still a bit overlapping (you can find part of horizontal axis ticklabel “j” is missing). Without setting DPI in session 0, everything looked fine but the size is larger.
In session 1, setting DPI to 96 or not will both produce an image in which two lines of labels were displayed correctly, but still a bit overlapping on horizontal axis ticklabels.
I hope these results help.
Thanks very much
ServerSide527:Yes normally we shouldn't need to reset DPI, it was only because the chart image works better with DPI value 120 in my session 0 (where the DPI is 120 by default). So I was thinking of rendering sheet by 96 DPI and when rendering charts I change the value back to 120. As long as chart image using 96 is correct, I will not need to reset DPI.
ServerSide527:I tested with Aspose.Cells 8.8.3.2 you provided, and attached the results. I found the labels were no longer overlapped that much in 8.8.3.2 when setting DPI to 96 in session 0, but the second line of labels were missing and still a bit overlapping (you can find part of horizontal axis ticklabel "j" is missing). Without setting DPI in session 0, everything looked fine but the size is larger.
ServerSide527:In session 1, setting DPI to 96 or not will both produce an image in which two lines of labels were displayed correctly, but still a bit overlapping on horizontal axis ticklabels. I hope these results help.
Hi Babar,
Thanks very much for your quick response.
I’ve just tested with Aspose.Cells 8.8.3.3 but all the issues remains (the outputs were exactly the same as what I attached last time using 8.8.3.2). To ensure I used the correct version, I also printed out the version number using CellsHelper.GetVersion() and it suggested it is 8.8.3.3.
Regarding what I mentioned the “overlapping on horizontal ticklabels”, I’ve attached a screenshot and highlighted the problematic area for you. You can see it was a lot better than when using 8.8.3.0 but still a little overlapping remains. This was not fixed in 8.8.3.3 either.
Thanks,
Hi John,
Worksheet sheet = book.Worksheets[0];
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
OnePagePerSheet = true,
VerticalResolution = 300,
HorizontalResolution = 300
};
sheet.Charts[0].ToImage(dir + “100PercentDisplay-withoutsettingDPIto96.emf”, options);