# Keep Rows Together Over Page Breaks

DsExcel enables you to keep some rows together over page breaks while exporting to a PDF file.

## Content

DsExcel allows you to keep a specified range of rows on the same page when exporting a worksheet to PDF. This prevents the range from being split by an automatic page break.
Define the rows as an [IRange](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IRange.html) collection and pass the collection to the [paginate()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#paginate) method. Then, use the returned pagination information with the [savePageInfosToPDF()](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/PrintManager.html#savePageInfosToPDF) method to export the PDF.

## Keep a Row Range Together

In the following example, the original pagination places rows 1-36 on the first page and rows 37-73 on the second page. Rows 36 and 37 must remain together. After pagination, row 36 moves to the second page:

* Page 1 contains rows 1-35.
* Page 2 contains rows 36-73.

```Java
// Initialize workbook.
Workbook workbook = new Workbook();
        
// Open Excel file.
workbook.open("KeepTogether.xlsx");
        
// Fetch default worksheet.
IWorksheet worksheet = workbook.getWorksheets().get(0);

/* The first page of the natural pagination is from 
   row 1st to 36th, the second page is from row 37th to 73rd */
List<IRange> keepTogetherRanges = new ArrayList<IRange>();

/* The row 37th and 38th need to keep together.
   So the pagination results are: the first page is from row 
   1st to 35th, the second page is from row 36th to 73rd*/
keepTogetherRanges.add(worksheet.getRange("36:37"));

// Create an instance of the PrintManager class.
PrintManager printManager = new PrintManager();

// Get the pagination information of the worksheet.
List<PageInfo> pages = printManager.paginate(worksheet, keepTogetherRanges, null);

// Save the modified pages into pdf file.
printManager.savePageInfosToPDF("KeepTogether.pdf", pages);
```