Documents for Excel, Java Edition Documentation
File Operations / Export to PDF / Control Pagination / Export Last Page Without Headers
In This Topic
    Export Last Page Without Headers
    In This Topic

    GcExcel Java enables users to export the last page of a PDF file without headers while keeping the headers intact in rest of the pages across the PDF file. For instance - While saving a workbook to a PDF file, you may sometimes have data in the last page of the PDF that doesn't need any headers. In such a scenario, this feature can be helpful in order to save the last page of the PDF without displaying any header information.

    In order to export the last page without headers while saving to a PDF file, you need to first get the default pagination by using the paginate() method of the PrintManager class. Then, you can use the setPageContent() method of the PageInfo class and the setTitleRowStart() method of the PageContentInfo class in order to modify the header index of the last page. When you are done, simply save your file using the savePageInfosToPDF() method.

    Using Code

    Refer to the following example code to allow users to save the last page of the PDF without any headers while exporting to a PDF file.

    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Open Excel file"ExcelData.xlsx");
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    // Create an instance of the PrintManager class
    PrintManager printManager = new PrintManager();
    // Rows to be repeated on the top of each page, while saving pdf
    // Get the default pagination information of the workbook
    List<PageInfo> pages = printManager.paginate(workbook);
    // Modify the print header of the last page
    pages.get(pages.size() - 1).getPageContent().setTitleRowStart(-1);
    // Save the modified pages into pdf file
    printManager.savePageInfosToPDF("ExportLastPageWithoutHeaders.pdf", pages);