Text is breaking into two page on page break

Hi Support,
we are using excel as source template and putting the data in excel and then rendering into pdf format.
While doing so we faced one issue where text is splitting into two pages. PFA .
Requirement is text should not break either it should come in previous page or in next page.
Please advice how to handle this. this is an urgent requirement.
Thanks in advance for your support.
.Pdf Page split issue with merge cells.PNG (47.4 KB)

@PolarisAP,
I have studied your presented scenario. No doubt it could be difficult to calculate where to put the printing page breaks when you are populating the data dynamically. Unfortunately, there is no hard and fast rule on how to calculate the page breaks however here a few tips that might help you in achieving your goals.

  • You can get the printing page breaks of an existing worksheet that will help you understand where the pages will break. You can use the Worksheet.GetPrintingPageBreaks method that will return an array of CellArea which in turn could tell you where the current page breaks are. You can use this information to move the breaks at your desired locations. You can also call the aforesaid method just before saving the spreadsheet so that the API could calculate the page breaks according to the amount of data and considering the formatting (font size) as well as the height of rows and widths of the columns, in case you are calling AutoFitRows & AutoFitColumns .
  • You can use the Worksheet.AddPageBreaks method or Add methods from HorizontalPageBreakCollection & VerticalPageBreakCollection classes to put the page breaks on the desired locations. At the bottom of this post, you will find the code snippet to add manual page breaks.

Other options is that you could use the discontinued print areas to achieve your goal. Please check the following piece of code and its resultant PDF. You will notice that each section is getting printed on a separate PDF page in predefined paper size.

Please note, the code is hard coding the print area settings, however, at the time of populating the data, you could extract this information and consequently formulate the string that could serve as PrintArea property. This is because, at the time of populating the data, you will have the information about the matrix (rows x columns) which is being effected.

var book = new Workbook(dir + “aspose formatting.xls”);
var sheet = book.Worksheets[0];
var pageSetup = sheet.PageSetup;
pageSetup.PrintArea = “A4:F7,A9:F9,A11:F11,A15:F35,A37:F41,A43:F43”;
book.Save(dir + “output.pdf”, Aspose.Cells.SaveFormat.Pdf);

In case the above provided solution is not acceptable to you, please update you sample spreadsheet with Excel to put manual page breaks (at positions where you wish them to be) and share the sample with us. Moreover, please tell us what do you want to do with blank rows, that is; do you wish them to be printed or skipped.