0

Using the MigraDoc and PDFSharp libraries, I have written vb.net code that produces a Title, subtitle followed by a 10 column table. I would like the table header row with continuation of the table rows data to show on page 2 and subsequent pages. I have tried several of the postings,e.g., Migradoc Header with table, but they do not work. What code can I add and where to resolve this issue. Here is my code.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Const embedding As PdfFontEmbedding = PdfFontEmbedding.Always
    Dim renderer As PdfDocumentRenderer = New PdfDocumentRenderer(embedding)
    Dim doc As Document = CreateDocument()
    renderer.Document = doc
    renderer.DocumentRenderer = renderer.DocumentRenderer
    renderer.RenderDocument()
    renderer.PdfDocument.Save("C:\MigraDoc.pdf")
 End Sub

Public Shared Function CreateDocument() As Document
    document = New Document()
    DefineStyles()
    CreatePage()
    FillContent()
    Return document
End Function

Private Shared Sub DefineStyles()
    Dim style As Style = document.Styles("Normal")
    style.Font.Name = "Arial"
    style = document.Styles(StyleNames.Header)
    style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right)
    style = document.Styles.AddStyle("Table", "Normal")
    style.Font.Name = "Arial"
    style.Font.Size = 9
    style = document.Styles.AddStyle("Reference", "Normal")
    style.ParagraphFormat.SpaceBefore = "5mm"
    style.ParagraphFormat.SpaceAfter = 0
    style.ParagraphFormat.TabStops.AddTabStop("16cm", TabAlignment.Right)
End Sub

Private Shared Sub CreatePage()
    Dim section As Section = document.AddSection()
    section.PageSetup.PageFormat = PageFormat.Letter
    section.PageSetup.PageWidth = Unit.FromPoint(612)
    section.PageSetup.PageHeight = Unit.FromPoint(792)
    section.PageSetup.TopMargin = 30
    section.PageSetup.LeftMargin = 28

    Dim paragraph As Paragraph = section.Headers.Primary.AddParagraph()
    paragraph = section.AddParagraph()
    Paragraph.Format.Font.Name = "Arial"
    paragraph.Format.Font.Size = 16
    paragraph.Format.SpaceBefore = 0
    paragraph.Format.SpaceAfter = 40
    paragraph.Format.Alignment = ParagraphAlignment.Center
    paragraph.AddFormattedText("My Text")

    paragraph = section.AddParagraph()
    paragraph.Format.SpaceBefore = 15
    paragraph.Style = "Reference"
    paragraph.AddFormattedText("more text")
    paragraph.AddTab()
    paragraph.AddDateField("MM.dd.yyyy")

    table = section.AddTable()
    table.Style = "Table"
    table.Borders.Color = Colors.Aqua
    table.Borders.Width = 0.25
    table.Borders.Left.Width = 0.5
    table.Borders.Right.Width = 0.5
    table.Rows.LeftIndent = 0

    Dim column As Column = table.AddColumn(25)
    column = table.AddColumn(35)
    column = table.AddColumn(95)
    column = table.AddColumn(85)
    column = table.AddColumn(95)
    column = table.AddColumn(40)
    column = table.AddColumn(30)
    column = table.AddColumn(50)
    column = table.AddColumn(50)
    column = table.AddColumn(50)

    Dim row As Row = table.AddRow()
    row.HeadingFormat = True
    row.Format.Alignment = ParagraphAlignment.Center
    row.Format.Font.Bold = True
    row.Shading.Color = Colors.Aqua
    row.Format.SpaceBefore = 3
    row.Format.SpaceAfter = 3
    row.Cells(0).AddParagraph("|_|")
    row.Cells(1).AddParagraph("Sail")
    row.Cells(2).AddParagraph("Name")
    row.Cells(3).AddParagraph("Type")
    row.Cells(4).AddParagraph("Skipper")
    row.Cells(5).AddParagraph("Club")
    row.Cells(6).AddParagraph("Rtg")
    row.Cells(7).AddParagraph("Finish")
    row.Cells(8).AddParagraph("Corrected")
    row.Cells(9).AddParagraph("1st+")
End Sub

Private Shared Sub FillContent()
    For i As Integer = 0 To 50 - 1
        Dim row1 As Row = table.AddRow()
        row1.HeadingFormat = True
        row1.Format.Font.Bold = False
        row1.Shading.Color = Colors.White
        row1.Format.SpaceBefore = 3
        row1.Format.SpaceAfter = 3
        row1.Cells(0).AddParagraph("1")
        row1.Cells(0).Format.Alignment = ParagraphAlignment.Center
        row1.Cells(1).AddParagraph("13241")
        row1.Cells(1).Format.Alignment = ParagraphAlignment.Left
        row1.Cells(2).AddParagraph("Score 33")
        row1.Cells(2).Format.Alignment = ParagraphAlignment.Left
        row1.Cells(3).AddParagraph("Santana 35")
        row1.Cells(3).Format.Alignment = ParagraphAlignment.Left
        row1.Cells(4).AddParagraph("Billy Bob")
        row1.Cells(4).Format.Alignment = ParagraphAlignment.Left
        row1.Cells(5).AddParagraph("BYC")
        row1.Cells(5).Format.Alignment = ParagraphAlignment.Left
        row1.Cells(6).AddParagraph("120")
        row1.Cells(6).Format.Alignment = ParagraphAlignment.Center
        row1.Cells(7).AddParagraph("15:16:55")
        row1.Cells(7).Format.Alignment = ParagraphAlignment.Center
        row1.Cells(8).AddParagraph("02:16:55")
        row1.Cells(8).Format.Alignment = ParagraphAlignment.Center
        row1.Cells(9).AddParagraph("00:00:00")
        row1.Cells(9).Format.Alignment = ParagraphAlignment.Center
    Next
End Sub

End Class

Ed Jenkins
  • 133
  • 10

0 Answers0