// Create a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("KeepTogether.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); workbook.open(this.getResourceStream("xlsx/KeepTogether.xlsx")); IWorksheet worksheet = workbook.getWorksheets().get(0); //The first page of the natural pagination is from row 1th to 37th, the second page is from row 38th to 73th. List keepTogetherRanges = new ArrayList(); //The row 37th and 38th need to keep together. So the pagination results are: the first page if from row 1th to 36th, the second page is from row 37th to 73th. keepTogetherRanges.add(worksheet.getRange("37:38")); //Create a PrintManager. PrintManager printManager = new PrintManager(); //Get the pagination information of the worksheet. List pages = printManager.paginate(worksheet, keepTogetherRanges, null); //Save the pages into pdf file. printManager.savePageInfosToPDF(outputStream, pages); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }