PDF Page Orientation Issue

Hi,


It looks like when I save an excel workbook as a PDF, the page orientation settings are lost. The attached code generates an excel workbook and a PDF of that workbook. The sheets in the excel workbook have their page orientation correctly set to portrait, but the PDF uses a landscape layout. I believe this was working correctly for me in a previous version of Aspose.Cells, but I can’t verify that definitively.

Code to reproduce this issue as well as some data that the code reads in is attached.

Thanks,
Eric

Hi,


Thanks for the template file and sample code.

Well, this is not an issue with Aspose.Cells APIs rather you have specified the attribute AllColumnsInOnePagePerSheet of PdfSaveOptions to “true” which would override your existing Portrait orientation because this property would try to render all columns on one page and does extend width of the PDF page(s). Please do not specify this attribute if you want your desired orientation.

Thank you.

In excel you are able to fit all columns on one page while keeping the portrait orientation. If you choose this option in excel, it shrinks the size of the content so that all columns fit.

Hi,


Well, see the following code segment that you may use instead, it would work according to your desired formatting:
e.g
Sample code:


foreach (Worksheet sheet in workbook.Worksheets)
{
sheet.PageSetup.Orientation = PageOrientationType.Portrait;
sheet.PageSetup.FitToPagesWide = 1;
sheet.PageSetup.FitToPagesTall = 0;
}

Also, do not use “AllColumnsInOnePagePerSheet” attribute.

Thank you.

That works.


Thanks,
Eric

Hi,


Good to know that it figures out your issue. Feel free to write us back in case you have further comments or questions, we will be happy to assist you soon.

Thank you.