We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Auto expand Excel content to A4 Paper's actual printable size using Aspose.Cells for .NET C# API

Hi. How can we expand the excel sheet content size to fit exactly in A4 size printable area? Currently the sheet we are having have content less than the A4 size printable area. Hence the resultant page size of pdf converted from excel is varying as per the sheet’s content size.


Thanks for your query.

Well, you may try to set your desired paper size for your sheet before rendering to PDF file format, see the following line of code for your reference:
Sample code:

worksheet.PageSetup.PaperSize = Aspose.Cells.PaperSizeType.PaperA4; 

Hope, this helps a bit.

I have tried the code above but still getting the different page size for 2 consecutive pdf pages.
Attached screen shot for more clarity.PDF-SAMPLE.png (52.4 KB)


Thanks for the screenshot.

Please share your template file, sample code (runnable) and output PDF file, we will check it soon. Please separate the issue and use only Aspose.Cells API to reproduce the issue in a simple test case.

Please note, if A4 paper size is set in page setup, it will work (the output PDF page size should be A4) if OnePagePerSheet/AllColumnsInOnePagePerSheet attribute is not set in PdfSaveOptions.