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 memory 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.
Aspose::Cells::Startup(); | |
U16String dataDir = u""; | |
// Create a sample workbook and add some data inside the first worksheet | |
Workbook workbook; | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
worksheet.GetCells().Get(u"P30").PutValue(u"This is sample data."); | |
// Save the workbook in memory stream | |
Vector<uint8_t> ms = workbook.SaveToStream(); | |
// Now load the workbook from memory stream with A5 paper size | |
LoadOptions opts(LoadFormat::Xlsx); | |
opts.SetPaperSize(PaperSizeType::PaperA5); | |
workbook = Workbook(ms, opts); | |
// Save the workbook in pdf format | |
workbook.Save(dataDir + u"LoadWorkbookWithPrinterSize-a5_out.pdf"); | |
// Now load the workbook again from memory stream with A3 paper size | |
opts = LoadOptions(LoadFormat::Xlsx); | |
opts.SetPaperSize(PaperSizeType::PaperA3); | |
workbook = Workbook(ms, opts); | |
// Save the workbook in pdf format | |
workbook.Save(dataDir + u"LoadWorkbookWithPrinterSize-a3_out.pdf"); | |
Aspose::Cells::Cleanup(); |