Free Support Forum - aspose.com

Save Workbook to PDF in Landscape Mode

Hi,

When saving a Workbook as a PDF type, is it possible to save it in landscape mode vs. portrait mode? And if so, could you please provide an example as to how to do it using the APIs? Thank you.

Hi,


Well, you may specify each worksheet’s orientation type to landscape in the workbook before rendering to PDF.
e.g
Sample code:

[C#]<o:p></o:p>

var workbook = new Workbook(@"e:\test2\Book1.xlsx");

foreach (Worksheet sheet in workbook.Worksheets)

{

sheet.PageSetup.Orientation = PageOrientationType.Landscape;

}

workbook.Save(@"e:\test2\out1.pdf");

[JAVA]

Workbook workbook = new Workbook("Book1.xlsx");

for (int i = 0; i < workbook.getWorksheets().getCount(); i++ )

{

workbook.getWorksheets().get(i).getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);

}

wb.save("out1.pdf");



Hope, this helps a bit.

Thank you.

Hi,

Is there a way to set it on the Book level so that you don’t have to loop through sheets? Also I marked this item as “Java”. Could you please provide the Java API version of the appropriate code snippet? Thanks.

Hi,


Thanks for your posting and using Aspose.Cells.

We are afraid, this is not a Workbook level setting as we have tested it in Microsoft Excel 2016. This is a Worksheet level setting only, so you will have to iterate all worksheets and set their orientation to landscape one by one. Besides, we have updated the code to Java code in our previous post for your help. It should help you to set the sheet orientation in Java successfully. Let us know your feedback.

Thank you both.