Documents for Excel .NET Edition | GCDocuments
File Operations / Export to PDF / Control Pagination / Delete Blank Pages From Middle
In This Topic
    Delete Blank Pages From Middle
    In This Topic

    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, GcExcel .NET 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 class and use the Paginate method to get the default pagination of the workbook. Now, you can use the HasPrintContent method to check whether the pages have content or not. 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 allow users to delete the blank pages in the middle while exporting to a PDF file.

    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Open Excel file
    // Create an instance of the PrintManager class
    PrintManager printManager = new PrintManager();
    // Get the natural pagination information of the workbook
    IList<PageInfo> pages = printManager.Paginate(workbook);
    // Remove empty pages
    IList<PageInfo> newPages = new List<PageInfo>();
    foreach (PageInfo page in pages)
      // True if there is content in the range to print
      if (printManager.HasPrintContent(page.PageContent.Range))
    // Update the page number and the page settings of each page
    // Save to PDF file
    printManager.SavePDF("DeleteBlankPagesIntheMiddle.pdf", newPages);