Free Support Forum - aspose.com

AllowBreakAcrossPages does not PDF properly with nested tables

We have a set of simple nested tables. Internally there are a set of tables with 10 rows and each of these tables need to be kept together. We have tried nesting each of these 10 tables in a single cell table with the AllowBreakAcrossPages set to false.If I save the document in Word and open the .docx file it looks perfect.If I save as PDF, the tables break across pages.

Sample code is attached.

Can this be fixed?

Todd

Hi Todd,

Thanks for your inquiry. Actually, to achieve what you need it is not necessary to use nested tables. It would be enough to use KeepWithNext option as shown in the code below:

Dim doc As New Document()

Dim wrdDoc As New DocumentBuilder(doc)

Dim HeaderRow As Aspose.Words.Tables.Row

Dim BodyRow As Aspose.Words.Tables.Row

Dim SingleRowTableRow As Aspose.Words.Tables.Row

wrdDoc.StartTable()

wrdDoc.InsertCell() ' title cell

wrdDoc.Write("Header Row")

HeaderRow = wrdDoc.CurrentParagraph.GetAncestor(GetType(Aspose.Words.Tables.Row))

wrdDoc.EndRow() ' title cell

For i As Integer = 1 To 10

wrdDoc.RowFormat.AllowBreakAcrossPages = False

' 10 row in table are keep togather

For j As Integer = 1 To 10

wrdDoc.Font.Size = 10

wrdDoc.InsertCell()

' enable keep with nex option for each paragraph except the last one in the sequence.

wrdDoc.ParagraphFormat.KeepWithNext = (j <> 10)

wrdDoc.Writeln(j)

wrdDoc.EndRow()

Next

Next

' set the header row to repeat

HeaderRow.RowFormat.HeadingFormat = True

wrdDoc.EndTable()

doc.Save("C:\Temp\out.docx")

doc.Save("C:\Temp\out.pdf")

Hope this helps.

Best regards,