Hi Aspose Dev -
I have an issue that has to do with table rows and page-breaks. I am dynamically creating
several tables within an aspose document object using builder. Most of these tables only
contain a few rows, but I would like to force a table to start at the beginning of the next page
rather than see some of the rows on page-1 and some on page-2. I set some properties to enforce this, but so far can’ t get it to work.This includes RowFormat.AllowBreakAcrossPages, ParagraphFormat.KeepWithNext, and ParagraphFormat.KeepTogether. I’d rather not track
the size of available page space and the number of rows to display in the next table, and
insert a PageBreak manually. It seems that only a property needs to be set for this.
Am I missing something basic?
Thanks for your help –
bob kells
Hi Bob,
Thanks for your inquiry.
You can force a page break by inserting a page break after the table. Please see the code below which achieves this.
// Create table
builder.StartTable();
builder.InsertCell();
builder.Write("Cell1");
builder.InsertCell();
builder.Write("Cell2");
builder.EndRow();
builder.InsertCell();
builder.Write("Cell3");
builder.InsertCell();
builder.Write("Cell4");
builder.EndRow();
builder.EndTable();
// Force page break at the end of the table
builder.InsertBreak(BreakType.PageBreak);
If you have any further queries, please feel free to ask.
Thanks,
Hi Adam -
Thanks for your reply. Sorry it took me so long to get back to this.
Actually, the solution to my problem was the following…
I had to set builder.ParagraphFormat.KeepWithNext = False on the last row of my table (which is blank). I had been assigning a value of True to all rows. This alerts aspose where to assign a page break when a table is about to be split across pages. I may have several small tables on one page, so it was difficult to know where to insert the manual page-break you describe above. Anyway, this seems to be working fine.
Thanks -
bk
Hi Bob,
Thanks for this additional information.
Ah my apologises, I misunderstood your first request. Yes, that is the correct solution to achieve what you are looking for when using KeepWithNext. It’s great you were able to resolve the issue.
Thanks,