Render WTable object on a new page if there is no enough space

Hello there,

I'm working with a WordDocument that will be converted to PDF once all the content is added.

Part of this content is related to table, and I used the WTable object (from DOCIO.DLS namespace).

Everything works great except that, if the page has not enough space for containing all the table content, then the table is splitted on two pages.

I tried to set the style options (please, note the instruction "tableStyle.TableProperties.AllowPageBreaks = false;")


{
string styleName = $"THeader_{Id}";
tableStyle = document.Styles.FindByName(styleName) as WTableStyle;
if (tableStyle == null)
{
tableStyle = document.AddTableStyle(styleName);
}
//Applies formatting for whole table.

tableStyle.CellProperties.Paddings.All = 5;
tableStyle.TableProperties.RowStripe = 1;
tableStyle.TableProperties.ColumnStripe = 1;
tableStyle.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
tableStyle.CharacterFormat.FontName = "Helvetica";
//Applies conditional formatting for first row.
ConditionalFormattingStyle firstRowStyle = tableStyle.ConditionalFormattingStyles.Add(ConditionalFormattingType.FirstRow);
firstRowStyle.CharacterFormat.Bold = true;
firstRowStyle.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Black;
firstRowStyle.CellProperties.BackColor = Syncfusion.Drawing.Color.White;

tableStyle.TableProperties.AllowPageBreaks = false;
}




but the resulting PDF shows the following behavior:



Isn't it the right way to avoid a page break within a table? What am I missing?


Thanks in advance


1 Reply

LB Lokesh Baskar Syncfusion Team March 18, 2022 12:25 PM UTC

Hi Rocco,

From the given details, we have found that your requirement is to avoid the table splitting across the pages in the document. To achieve your requirement we suggest to enable the KeepFollow API for the paragraph that presents in the table cell. Please refer to the below code snippet: 
// Checks whether the paragraph is in cell. 
if (paragraph.IsInCell) 
// Whether is need to keep paragraph together on a page or in a column. 
paragraph.ParagraphFormat.KeepFollow = true; 


We have prepared the sample application to achieve your requirement please refer to the sample given below.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/DocIOSample1300752306.zip  
Lokesh B

 


Loader.
Up arrow icon