Load Workbook with specified Printer Paper Size
Load Workbook with specified Printer Paper Size
The following sample code illustrates the usage of LoadOptions.setPaperSize() method. It first creates a workbook, then saves it in byte array stream in XLSX format. Then it loads it with A5 paper size and saves it in PDF format. Then it loads it again with A3 paper size and saves it again in PDF format. If you open the output PDFs and check their paper size, you will see they are different. One is A5 and the other is A3. Please download the A5 output PDF and A3 output PDF generated by the code for your reference.
// 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(LoadWorkbook.class); | |
// Create a sample workbook and add some data inside the first worksheet | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
worksheet.getCells().get("P30").putValue("This is sample data."); | |
// Save the workbook in memory stream | |
ByteArrayOutputStream baout = new ByteArrayOutputStream(); | |
workbook.save(baout, SaveFormat.XLSX); | |
// Get bytes and create byte array input stream | |
byte[] bts = baout.toByteArray(); | |
ByteArrayInputStream bain = new ByteArrayInputStream(bts); | |
// Now load the workbook from memory stream with A5 paper size | |
LoadOptions opts = new LoadOptions(LoadFormat.XLSX); | |
opts.setPaperSize(PaperSizeType.PAPER_A_5); | |
workbook = new Workbook(bain, opts); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output-a5.pdf"); | |
// Now load the workbook again from memory stream with A3 paper size | |
opts = new LoadOptions(LoadFormat.XLSX); | |
opts.setPaperSize(PaperSizeType.PAPER_A_3); | |
workbook = new Workbook(bain, opts); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output-a3.pdf"); |