Excel to PDF conversion - Set custom page size in .NET

In aspose.Cell, i can set PageSize by below code.


sheet.PageSetup.PaperSize = Aspose.Cells.PaperSizeType.PaperA3;

But i have Width and Height, How can i set with and height of a excel sheet?

Hi,

Thanks for your posting and considering Aspose.Cells.

We are afraid, you cannot set custom page size by specifying your own width and height. This feature is not available both in MS-Excel and Aspose.Cells.

You will have to set default page sizes defined by Aspose.Cells.PaperSizeType.

Hi,


Here i convert excel page to pdf.For that i need to set page size on output pdf file.
Currently i used to set page size via

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inputFilePath);
sheet[0].PageSetup.PaperSize = Aspose.Cells.PaperSizeType.PaperA3;
workbook.Save(outputFile, Aspose.Cells.SaveFormat.Pdf);

Is any way to set custom margin for output pdf?


Hi Varun,


You may use the PageSetup class to set margins as per your requirements. Please check the below linked detailed article on this subject.
http://www.aspose.com/docs/display/cellsnet/Setting+Margins

Hi, I wrongly entered data,

Is any way to set custom PageSize for output pdf?

Hi Varun,


I am sorry to say that Aspose.Cells APIs do not provide any means to set custom page size. This is due to the reason that MS Excel it self does not offer such feature, and Aspose.Cells follow MS Excel’s guidelines and standards in its implementation.

Thank you for your understanding.

@varunkumar

Thanks for considering Aspose APIs.

Please use the Worksheet.PageSetup.CustomPaperSize() method with the most recent version i.e. 17.11.6 for your needs. Please see the following code, its output Pdf and screenshot for a reference.

output-5x6-inches.zip (9.7 KB)

C#

//Create workbook
Workbook wb = new Workbook();

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Write some data in cell B4
ws.Cells["B4"].PutValue("This is sample data.");

//Set custom paper size, it is 5 x 6 inches
ws.PageSetup.CustomPaperSize(5, 6);

//Save it as pdf
wb.Save("output-5x6-inches.pdf");

Screenshot