Conditionally insert new page break when combining tables

Hi,I have a process that combines multiple tables into a single destination table that is then saved as a PDF.Under certain conditions, I would like to add a new page break between tables and I need help inserting that condition. This is my module -

Private Sub CombineTables(ByRef dstTable As Tables.Table, ByVal srcTable As Tables.Table)Try
Dim srcRows() As Node = srcTable.Rows.ToArray
    Dim Importer As NodeImporter = New NodeImporter(srcTable.Document, dstTable.Document, ImportFormatMode.UseDestinationStyles)
    ' (I would like to insert page break here)

    For Each row As Tables.Row In srcRows
        Dim dstRow As Node = Importer.ImportNode(row, True)
        dstTable.AppendChild(dstRow)

    Next
    Catch ex As Exception
    End Try
End Sub

Hi Douglas,

Thanks for your inquiry.

Actually in a word document a table cannot contain a page break. When you insert a page break inside a table in Microsoft Word it is split into two separate tables. This means if you are using a header row it will not appear on the second table as the tables are different.

You can achieve the same behavior by importing the entire source table and inserting a paragraph containing a page break in between. Please see the code below.

dstTable.ParentNode.InsertAfter(importer.ImportNode(srcTable, true), dstTable)
Dim para as Paragraph = new Paragraph(dstTable.Document)
para.AppendChild(new Run(dstTable.Document, ControlChar.PageBreak))
dstTable.ParentNode.InsertAfter(para, dstTable)

Thanks,

Hi,
One aspect of my particular application was that the destination table I was assembling was a composite table that consisted of a number of different source tables. I wanted them to be assembled in a particular sequence.
The solution above does have the page break before the table, but they are all added to the end. I wanted to maintain the sequence.
Do I need to break my composite table idea apart and make separate tables to be able to control when I wanted a page break?
Regards,
Doug Kemp

Hi Doug,

Thanks for this additional information. Yes, I’m afraid you will need to have separate tables in order to have a page break in between.

Regarding the issue with the ordering I’m afraid I’m not sure what you mean, could you please attach a document and some code which demonstrates the issue? We will take a look at help you further.

Thanks,

Hi,
I am attaching a zip file with some of the building block ms word .doc files and the resulting document in the form of a pdf.
Regards,
Doug

This is the code section. The work is done in the BuildOffenseReportPDF function.

Hi Doub,

Thanks for this additional information.

I’m afraid I can’t spot the issue with your code, the source table is inserted after the destination table when using the code I proposed above. Could you please clarify the issue you are having?

Thanks,