Margin changes in PDF after latest nuget package

Shared.zip (325.2 KB)

             Workbook workbook = new Workbook(filepath);
            //Validate in case file is corrupted. Normally excel file should have at least 1 sheet
            if (workbook.Worksheets.Any())
            {
                 var worksheet = workbook.Worksheets[0];
                worksheet.AutoFitRows();
                //Make all worksheet visible false except for first one for pdf conversion 
                // If there is any value in workSheetArray mark thse worksheet indexes as visible
                //Item.Index starts at 0 so must add +1 to comapare with workSheetArray values
                foreach (Worksheet item in workbook.Worksheets)
                {
                    item.IsVisible = workSheetArray==null || !workSheetArray.Any()? item.Index == 0: workSheetArray.Contains((item.Index + 1).ToString());
                }

            }  
            var stream = workbook.SaveToStream();
            workbook.Save(convertedPdfTempFile, SaveFormat.Pdf);

OldVersion: Aspose.Cells.dll ( 2016 )
NewVersion:

@rbalaji007

Please also share your source file for us to reproduce the issue. We will check it soon.

Thank you Team for the quick response.
Here goes the source file. (Test1.xlsx from Test1.zip)
Test1.zip (104.3 KB)

I tried using the following sample code with your provided Excel file using our latest available version, Aspose.Cells for .NET v22.2 (please try it) and it works absolutely fine. Please find attached (below) the output PDF file.
e.g.
Sample code:

Workbook workbook = new Workbook("e:\\test2\\test1.xlsx");
foreach (Worksheet item in workbook.Worksheets)
{
     item.AutoFitRows();
}
workbook.Save("e:\\test2\\out1.pdf", SaveFormat.Pdf);

out1.pdf (177.2 KB)

Thank you Amjad.

When I call SaveToStream first and later call Save method , PDF alignment shows some issues .

var stream = workbook.SaveToStream();
workbook.Save(convertedPdfTempFile, SaveFormat.Pdf);

When I call Save first and then call SaveToStream, the PDF alignment looks good.
workbook.Save(convertedPdfTempFile, SaveFormat.Pdf);
var stream = workbook.SaveToStream();

@rbalaji007

The method workbook.SaveToStream() saves workbook to xls(Excel 2003) format, however your source file is xlsx(Excel 2007) format. Some default data is changed during this process. For your case, the paper size is changed from Letter to A4.

Could you please share more detail that why var stream = workbook.SaveToStream();(It seems that the result stream is not used in your code snippet.) is called before saving to pdf?

Thank you.
This is a library wrapper code. The calling application will make use of the stream object and store it as a xlsx file.

Is there a way to specify the format version ( Excel 2013/Excel 2019) in the SaveToStream API?

@rbalaji007,

SaveToStream method saves the file in XLS (older) file format, you cannot save to XLSX file format using this method. To save to newer Excel (XLSX) file format, you may use Workbook.Save (Stream, SaveOptions) overloaded method.