// Create a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("ManageHeadersOnDifferentPages.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); workbook.open(this.getResourceStream("xlsx/MultipleHeaders.xlsx")); IWorksheet worksheet = workbook.getWorksheets().get(0); List repeatSettings = new ArrayList(); //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 "B91:F189" is "$91:$91" RepeatSetting repeatSetting2 = new RepeatSetting(); repeatSetting2.setTitleRowStart(88); repeatSetting2.setTitleRowEnd(88); repeatSetting2.setRange(worksheet.getRange("B89:F149")); repeatSettings.add(repeatSetting2); //Create a PrintManager. PrintManager printManager = new PrintManager(); //Get the pagination information of the worksheet. List pages = printManager.paginate(worksheet, null, repeatSettings); //Save the modified pages into pdf file. printManager.savePageInfosToPDF(outputStream, pages); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }