Fit All Worksheet Columns on Single PDF Page

Fit Worksheet Columns on Single PDF Page

PdfSaveOptions.setAllColumnsInOnePagePerSheet ensures that all columns of a worksheet are rendered to a single PDF page, although rows may expand to several pages depending upon the data in worksheet.

The sample code below shows how to use the PdfSaveOptions.setAllColumnsInOnePagePerSheet property to render a large worksheet of 100 columns.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FitAllWorksheetColumns.class);
// Create and initialize an instance of Workbook
Workbook book = new Workbook(dataDir + "TestBook.xlsx");
// Create and initialize an instance of PdfSaveOptions
PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.PDF);
// Set AllColumnsInOnePagePerSheet to true
saveOptions.setAllColumnsInOnePagePerSheet(true);
// Save Workbook to PDF fromart by passing the object of PdfSaveOptions
book.save(dataDir + "output.pdf", saveOptions);