Documents for Excel, Java Edition Documentation
File Operations / Export to PDF / Control Pagination / Export Different Headers On Different Pages
In This Topic
    Export Different Headers On Different Pages
    In This Topic

    GcExcel Java enables users to export different headers on different pages of the PDF file. This feature is useful especially when you have different information on each page of the PDF file and you want to provide different headers to each page of the PDF. 

    In order to configure different headers for different pages in the PDF file, you can use the setTitleRowStart() method, the setTitleRowEnd() method, and other methods of the RepeatSetting class. When you are done, simply create an instance of the PrintManager class, get the default pagination information using the paginate() method and finally save your PDF file using the savePageInfosToPDF() method.   

    Using Code

    Refer to the following example code in order to export different headers on different pages while exporting to a PDF file.

    Java
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
            
    // Open Excel file
    workbook.open("MultipleHeaders.xlsx");
            
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    List<RepeatSetting> repeatSettings = new ArrayList<RepeatSetting>();
    
    // The title rows of the "B2:F87" is "$2:$2"
    RepeatSetting repeatSetting = new RepeatSetting();
    repeatSetting.setTitleRowStart(1);
    repeatSetting.setTitleRowEnd(1);
    repeatSetting.setRange(worksheet.getRange("B2:F87"));
    repeatSettings.add(repeatSetting);
    
    // The title rows of the "B89:F146" is "$89:$89"
    RepeatSetting repeatSetting2 = new RepeatSetting();
    repeatSetting2.setTitleRowStart(88);
    repeatSetting2.setTitleRowEnd(88);
    repeatSetting2.setRange(worksheet.getRange("B89:F146"));
    repeatSettings.add(repeatSetting2);
    
    // Create an instance of the PrintManager class 
    PrintManager printManager = new PrintManager();
    worksheet.getPageSetup().setRightMargin(10);
    
    // Get the pagination information of the worksheet
    List<PageInfo> pages = 
    printManager.paginate(worksheet, null, repeatSettings);
    
    // Save the modified pages into pdf file
    printManager.savePageInfosToPDF("ManageHeadersOnDifferentPages.pdf", pages);