Document Solutions for Excel, Java Edition | Document Solutions
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

    DsExcel 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.

    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Open Excel file"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();
    // The title rows of the "B89:F146" is "$89:$89"
    RepeatSetting repeatSetting2 = new RepeatSetting();
    // Create an instance of the PrintManager class 
    PrintManager printManager = new PrintManager();
    // 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);