[]
        
(Showing Draft Content)

Export Specific Pages To PDF

GcExcel .NET enables users to export only some specific worksheets in the workbook (and not the entire workbook) into the pages of the PDF file.

This feature is useful especially when you have a workbook containing large number of worksheets. For instance - While saving to a PDF file, you may not want to export the entire workbook containing multiple worksheets and want only some important worksheets to be saved to the PDF file. In this scenario, you can use this feature to generate a custom PDF file as per your requirements.

In order to export specific pages to the PDF file, create an instance of the PrintManager class and get the default pagination using the Paginate() method. Next, you need to specify the pages that you want to export or print. Finally, call the UpdatePageNumberAndPageSettings() method in order to update the indexes of the page number and the page settings for each page. When you are done, simply save your PDF file using the SavePDF() method.

Using Code

Refer to the following example code to export some specific pages to the PDF file.

// Initialize workbook
Workbook workbook = new Workbook();
        
// Open Excel file
workbook.Open("PrintSpecificPDFPages.xlsx");

// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();

// Get the natural pagination information of the workbook
IList pages = printManager.Paginate(workbook);

// Pick some pages to print
IList newPages = new List();
newPages.Add(pages[0]);
newPages.Add(pages[2]);

/* Update the page number and the page settings of 
   each page. The page number is continuous */
printManager.UpdatePageNumberAndPageSettings(newPages);

// Save the  pages into PDF file
printManager.SavePDF(@"PrintSpecificPages.pdf", newPages);