Aspose.Cells EvaluatedPageCount not working correctly in Linux

Hi,
I am using the Aspose.Cells Ver 24.40 and compiling my C# code for both Windows and Linux deployments.

Below is a segment of my code which is intended to avoid the scenario whereby occasionally a small vertical slither of a page is printed on a separate page – this is achieved by accessing if the Evaluated Page Count is one (1), and if so, setting FitToPagesWide = 1 to ensure all columns are scaled slightly (if necessary) to fit into the one page.

Of course, if the Evaluated Page Count is 2 or more, I do not want to set FitToPagesWide = 1.

My issue is that this works fine under Windows, but not under Linux. You will see that I have added a Console.Writeline statement.

When I use an input file which I know has an Evaulated Page Count of 1, I get the following message echoed…

  • For Windows – EvaluatedPageCount: 1
  • For Linux – EvaluatedPageCount: 2

This is the code segment.

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
SheetPrintingPreview preview;

// if Print Preview Evaluated Page Count is one (1), ensure the page is not broken over 2 pages before saving as PDF
foreach (Worksheet wrkSheet in wrkBook.Worksheets)
{
preview = new SheetPrintingPreview(wrkSheet, imgOptions);
Console.WriteLine(“EvaluatedPageCount: {0}”, preview.EvaluatedPageCount);
if (preview != null && preview.EvaluatedPageCount == 1)
{
wrkSheet.PageSetup.FitToPagesWide = 1;
wrkSheet.PageSetup.FitToPagesTall = 0;
}
}
wrkBook.Save(tempExcelPdf);

I’m pretty sure this is a bug in Aspose.Cells SheetPrintingPreview.EvaluatedPageCount as implemented for Linux.

Can you assist please?

@DS8062
Would you like to provide your sample file? We will check it soon.

Hi John,
I assume you mean a sample Excel file, is that correct?
Regards
Darryl

@DS8062
You are right. Because your sample file obtained different results on Windows and Linux, it is very helpful for us to locate the issue.

Hi John,

Please see attached ZIP file containing Example.xlsx – it has 4 tabs each of which correctly evaluates as 1 page per tab in Windows, and as 2 pages per tab in Linux.

Regards
Darryl

Example.zip (128.0 KB)

@DS8062 ,

Please aslo output/print the column width:

Workbook wrkBook = new Workbook("Example.xlsx");
Console.WriteLine(wrkBook.DefaultStyle.Font);

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
SheetPrintingPreview preview;

// if Print Preview Evaluated Page Count is one (1), ensure the page is not broken over 2 pages before saving as PDF
foreach (Worksheet wrkSheet in wrkBook.Worksheets)
{
    Console.WriteLine("Column 0 width: {0}", wrkSheet.Cells.GetColumnWidthPixel(0));

    preview = new SheetPrintingPreview(wrkSheet, imgOptions);
    Console.WriteLine("EvaluatedPageCount: {0}", preview.EvaluatedPageCount);
}

On our side, the output is same on both Windows and Linux: EvaluatedPageCount: 1

Aspose.Cells.Font [ Calibri; 11; Regular; Color [A=255, R=0, G=0, B=0] ]
Column 0 width: 64
EvaluatedPageCount: 1
Column 0 width: 215
EvaluatedPageCount: 1
Column 0 width: 200
EvaluatedPageCount: 1
Column 0 width: 212
EvaluatedPageCount: 1
Column 0 width: 100
EvaluatedPageCount: 0

Hi John,

I’ve found the problem – initially, in the absence of having Calibri font on Linux, I had specified a close match suggested on the web: Carlito font. I’ve now sourced and installed Calibri on Linux.

So, this is with Windows - all as expected:

Column 0 width: 64
EvaluatedPageCount: 1
Column 0 width: 215
EvaluatedPageCount: 1
Column 0 width: 200
EvaluatedPageCount: 1
Column 0 width: 212
EvaluatedPageCount: 1
Column 0 width: 100
EvaluatedPageCount: 0

This is with Linux using Carlito font - slightly different pixel widths, forcing the EvaluatedPageCount to equal 2:

Column 0 width: 69
EvaluatedPageCount: 2
Column 0 width: 245
EvaluatedPageCount: 2
Column 0 width: 228
EvaluatedPageCount: 2
Column 0 width: 242
EvaluatedPageCount: 2
Column 0 width: 114
EvaluatedPageCount: 0

This is Linux with Calibri font - now as expected, i.e. the same as Windows (or similar, interestingly the first result is 61 pixels vs 64 pixels for Windows):

Column 0 width: 61
EvaluatedPageCount: 1
Column 0 width: 215
EvaluatedPageCount: 1
Column 0 width: 200
EvaluatedPageCount: 1
Column 0 width: 212
EvaluatedPageCount: 1
Column 0 width: 100
EvaluatedPageCount: 0

In summary, problem solved – need to have exactly the same font available in Linux (makes sense when you think about it) – near match is not good enough.

Thanks for your super quick responses - much appreciated.

Regards
Darryl

@DS8062 ,

How did you change the font in the source file? It seems that you changed the source file in the Linux?

@DS8062
You are welcome. I’m glad your issue has been resolved. If you have any questions, please feel free to contact us.

Hi John,

In my code, I specified a default font for Linux in an IF statement that looks at what OS is present. This default font is intended to accommodate the scenario where any given font isn’t available.

In the first instance Calibri wasn’t available in my Linux environment and at that stage Carlito was specified as the default font, so Carlito was substituted for Calibri in Example.xlsx.

Subsequently, when I installed Calibri on my Linux environment, font substitution was no longer required.

Regards
Darryl

@DS8062,

Yes, fonts used in the workbook are compulsory for evaluating and rendering worksheet pages, so they should be installed in your environment and substitution is not required.