DsExcel .NET enables users to keep some rows together over page breaks while exporting to a PDF file.
This feature is useful especially when you have data lying in large number of rows in the worksheet that you want to export to a PDF file. For instance - let's say you have a spreadsheet having multiple groups of rows that are often hidden, but ultimately modify the number of pages and page breaks while printing. Now, you want to export your Excel file to PDF in such a way that it keeps some groups of rows together so that they don't split across page breaks or pages when the print operation is executed. In such a scenario, it is extremely helpful to utilize this feature to achieve flawless printing experience and accurate content publishing while exporting to the PDF file.
In order to keep some groups of rows together over page breaks, you need to first create a cell range including the rows that you want to show together in the PDF file. Next, create an instance of the PrintManager class and use the Paginate() method to ensure the desired rows are displayed together. When you are done, simply save your PDF file using the SavePDF() method.
Refer to the following example code to allow users to keep some rows together over page breaks while exporting to a PDF file.
C# |
Copy Code |
---|---|
// Initialize workbook Workbook workbook = new Workbook(); // Open Excel file workbook.Open("KeepTogether.xlsx"); // Fetch default worksheet IWorksheet worksheet = workbook.Worksheets[0]; /* The first page of the natural pagination is from row 1st to 36th the second page is from row 37th to 73rd */ IList<IRange> keepTogetherRanges = new List<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.Range["36:37"]); // Create an instance of the PrintManager class PrintManager printManager = new PrintManager(); // Get the pagination information of the worksheet IList<PageInfo> pages = printManager.Paginate(worksheet, keepTogetherRanges, null); // Save the modified pages into PDF file printManager.SavePDF(@"KeepTogether.pdf", pages); |