// Create a pdf file stream using FileStream outputStream = new FileStream("KeepTogether.pdf", FileMode.Create); //create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); Stream fileStream = this.GetResourceStream("xlsx\\KeepTogether.xlsx"); workbook.Open(fileStream); IWorksheet worksheet = workbook.Worksheets[0]; //The first page of the natural pagination is from row 1th to 37th, the second page is from row 38th to 73th. IList<IRange> keepTogetherRanges = new List<IRange>(); //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.Range["37:38"]); //Create a PrintManager. GrapeCity.Documents.Excel.PrintManager printManager = new GrapeCity.Documents.Excel.PrintManager(); //Get the pagination information of the worksheet. IList<PageInfo> pages = printManager.Paginate(worksheet, keepTogetherRanges, null); //Save the pages into pdf file. printManager.SavePDF(outputStream, pages); // close the pdf stream outputStream.Close();
' Create a pdf file stream Dim outputStream = File.Create("KeepTogether.pdf") ' Create a new Workbook Dim workbook As New Workbook Dim fileStream = GetResourceStream("KeepTogether.xlsx") workbook.Open(fileStream) Dim worksheet = workbook.Worksheets(0) 'The first page of the natural pagination is from row 1th to 37th, the second page is from row 38th to 73th. '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. Dim keepTogetherRanges As New List(Of IRange) From { worksheet.Range("37:38") } 'Create a PrintManager. Dim printManager As New Excel.PrintManager 'Get the pagination information of the worksheet. Dim pages = printManager.Paginate(worksheet, keepTogetherRanges, Nothing) 'Save the pages into pdf file. printManager.SavePDF(outputStream, pages) ' close the pdf stream outputStream.Close()