# Export Selected Pages and Remove Blank Pages

Use DsExcel to export only some specific worksheets in the workbook into the pages of the PDF file.

## Content

DsExcel allows users to export only specific worksheets in a workbook (instead of the entire workbook) to PDF pages, and also to scan for and remove blank pages in the PDF.

## Export Specific Pages to PDF

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](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html) class and get the default pagination using the [paginate()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#paginate) method. Next, you need to specify the pages that you want to export or print. Finally, call the [updatePageNumberAndPageSettings()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#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 [savePageInfosToPDF()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#savePageInfosToPDF) method.
Refer to the following example code to export some specific pages to the PDF file.

```Java
// 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
List<PageInfo> pages = printManager.paginate(workbook);

// Pick some pages to print
List<PageInfo> newPages = new ArrayList<PageInfo>();
newPages.add(pages.get(0));
newPages.add(pages.get(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.savePageInfosToPDF("PrintSpecificPages.pdf", newPages);
```

## Remove Blank Pages

While exporting a workbook to a PDF file, sometimes you may encounter a couple of extra pages that are completely blank. In a workbook with large number of worksheets, it is extremely difficult to find out which pages are empty and even more time-consuming to delete them from the middle without impacting the pagination.
In order to avoid printing and publishing of blank pages, DsExcel enables users to scan through the pages of the PDF, find out which pages are blank and then exclude the blank pages from the middle while also updating the pagination information accurately.
For removing blank pages from your PDF file, you need to first create an instance of the [PrintManager](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html) class and use the [paginate()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#paginate) method to get the default pagination of the workbook. Now, you can use the [hasPrintContent()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#hasPrintContent) method to check whether the pages have content or not. Finally, call the [updatePageNumberAndPageSettings()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#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 [savePageInfosToPDF()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#savePageInfosToPDF) method.
Refer to the following example code to allow users to delete the blank pages in the middle while exporting to a PDF file.

```Java
// Initialize workbook
Workbook workbook = new Workbook();

// Open Excel file
workbook.open("DeletingBlankPages.xlsx");

// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();
        
// Get the default pagination information of the workbook
List<PageInfo> pages = printManager.paginate(workbook);

// Remove empty pages
List<PageInfo> newPages =new ArrayList<PageInfo>();
for(PageInfo page : pages)
{
    // True if there is content in the range to print
    if(printManager.hasPrintContent(page.getPageContent()
        .getRange()))
    {
        newPages.add(page);
    }
}

// Update the page number and the page settings of each page
printManager.updatePageNumberAndPageSettings(newPages);

// Save to PDF file
printManager.savePageInfosToPDF("DeleteBlankPagesFromMiddle.pdf", newPages);
```