aspose-cells / Aspose.Cells-for-Java

Aspose.Cells for Java examples, plugins and showcases
https://products.aspose.com/cells/java
MIT License
148 stars 102 forks source link

How to customize the paper size when converting Excel to PDF #62

Open aiden-less opened 2 years ago

aiden-less commented 2 years ago

When excel is converted to PDF, the default paper size is A4. How can I realize the custom size (such as 15cm*5cm)?

amjad-sahi commented 2 years ago

Please use the PageSetup.customPaperSize() method with the most recent version/fix: Aspose.Cells for Java v22.6 for your needs. Please see the following code for your reference. e.g. Sample code:

//Create workbook
Workbook workbook = new Workbook("f:\\files\\Book1.xlsx");

//Access first worksheet
Worksheet ws = workbook.getWorksheets().get(0);

//Set custom paper size, you need to convert cm to inches
ws.getPageSetup().customPaperSize(1.97,5.9);

//Save it as pdf
workbook.save("out1.pdf");