Limit the Number of Pages Generated - Excel to PDF Conversion
Contents
[
Hide
]
Sometimes, you want to print a range of pages to an output PDF file. Aspose.Cells has the ability to set a limit on how many pages are generated when converting an Excel spreadsheet to the PDF file format.
Limiting the Number of Pages Generated
The following example shows how to render a range of pages (3 and 4) in a Microsoft Excel file to PDF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Workbook wb = new Workbook(dataDir+ "TestBook.xlsx"); | |
// Instantiate the PdfSaveOption | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// Print only Page 3 and Page 4 in the output PDF | |
// Starting page index (0-based index) | |
options.PageIndex = 3; | |
// Number of pages to be printed | |
options.PageCount = 2; | |
// Save the PDF file | |
wb.Save(dataDir+ "outPDF1.out.pdf", options); |
If the spreadsheet contains formulas, it is best to call Workbook.CalculateFormula() just before rendering it to PDF. Doing ensures that formula dependent values are recalculated, and the correct values are rendered in the output file.