PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 12:35 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Tables and headers
PostPosted: Thu Mar 26, 2015 6:44 pm 
Offline

Joined: Thu Mar 26, 2015 6:23 pm
Posts: 6
Hi All,

I'm new to PDFSharp & Migradoc. I'm trying create a document more or less like an invoice.
I fix the Header and footer, I begin the document with some normal paragraph and then I start a table.

On the first page it works perfectly but when it split the table on the second page it doesn't print the header, it continues with the table and correctly closes the page with footer.

Why it doesn't print the header?

Could I manage manually the table split?

Thanks for your help


Top
 Profile  
Reply with quote  
 Post subject: Re: Tables and headers
PostPosted: Thu Mar 26, 2015 9:51 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
Hi!

Maybe the header is hidden under the table, maybe the header was not set correctly.

You don't show any code.
viewtopic.php?f=2&t=832

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
 Post subject: Re: Tables and headers
PostPosted: Fri Mar 27, 2015 11:43 am 
Offline

Joined: Thu Mar 26, 2015 6:23 pm
Posts: 6
Hi thank you for your answer.

In the following code you can see the 3 functions I use to define the headers, to create the table and to add rows to the created table.

I can take advantage of your patience to figure out if I wrote nonsense? thank you

===============================================================

Code:
Public Sub DefineHeader(ByVal Filename As String, Optional ByVal Width As Single = 0, Optional ByVal Height As Single = 0, Optional LeftPosition As Single = 0, Optional TopPosition As Single = 0)

        Dim section As Section = _document.LastSection()

        If _OddAndEvenPagesHeaderFooter Then
            Dim header As HeaderFooter = section.Headers.Primary
            header.AddParagraph(vbTab & "Odd Page Header")

            header = section.Headers.EvenPage
            header.AddParagraph("Even Page Header")
        Else
            Dim header As HeaderFooter
            If Filename <> "" Then
                header = section.Headers.Primary
                Dim headerImg = header.AddImage(theDirectory & "\images\" & Filename)

                If Width <> 0 Then headerImg.Width = Unit.FromCentimeter(Width)
                If Height <> 0 Then headerImg.Height = Unit.FromCentimeter(Height)
                If LeftPosition <> 0 Then headerImg.Left = Unit.FromCentimeter(LeftPosition)
                If TopPosition <> 0 Then headerImg.Top = Unit.FromCentimeter(TopPosition)
                _currHeight = headerImg.Height.Centimeter
            End If
        End If

    End Sub
================================================================
Code:
Public Function CreateTable(ByVal Intestazione() As String, ByVal ColsWidth() As Single, ByVal ColsAlignment() As Integer, ByVal Top As Single) As MigraDoc.DocumentObjectModel.Tables.Table
        Dim Table = _document.LastSection.AddTable

        Table.Borders.Width = 0.5
        Table.Format.Font.ApplyFont(_currFont)

        '        table.Format.SpaceBefore = Unit.FromCentimeter(Top)
        For i = 0 To ColsWidth.Count - 1
            Dim column = Table.AddColumn(Unit.FromCentimeter(ColsWidth(i)))
            column.Format.Alignment = ColsAlignment(i)
        Next

        Dim row = Table.AddRow()
        row.Shading.Color = Colors.White
        row.HeadingFormat = True
        Dim MaxRowHeight As Single = 0

        For i = 0 To Intestazione.Count - 1
            Dim cell = row.Cells(i)
            cell.AddParagraph(Intestazione(i))
            Dim rowheight As Single
            GetTextMeasure(Intestazione(i))

            rowheight = (_currWidth / ColsWidth(i)) + 1
            rowheight *= _currHeight

            MaxRowHeight = IIf(MaxRowHeight < rowheight, rowheight, MaxRowHeight)

        Next
        row.Height = Unit.FromCentimeter(MaxRowHeight)
        row.HeightRule = Tables.RowHeightRule.Exactly

        _currHeight += MaxRowHeight

        Return Table

    End Function
===================================================================
Code:
Public Sub AddRowTable(ByRef Table As MigraDoc.DocumentObjectModel.Tables.Table, ByVal CellContent() As String, ByVal ColsAlignment() As Integer, Optional ByVal Top As Single = 0, Optional ByVal PageBreak As Boolean = False)
        Table.Borders.Width = 0.5
        Table.Format.Font.ApplyFont(_currFont)

        Dim row = Table.AddRow()
        row.Shading.Color = Colors.White
        row.HeadingFormat = False
        row.Format.PageBreakBefore = PageBreak
        Dim MaxRowHeight As Single = 0

        For i = 0 To CellContent.Count - 1
            Dim cell = row.Cells(i)
            cell.AddParagraph(CellContent(i))
            cell.Format.Alignment = ColsAlignment(i)

            Dim rowheight As Single

            GetTextMeasure(CellContent(i))
            rowheight = (_currWidth / row.Item(i).Column.Width.Centimeter) + 1
            rowheight *= _currHeight

            MaxRowHeight = IIf(MaxRowHeight < rowheight, rowheight, MaxRowHeight)

        Next
        row.Height = Unit.FromCentimeter(MaxRowHeight)
        row.HeightRule = Tables.RowHeightRule.Exactly

        _currHeight += MaxRowHeight

    End Sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Tables and headers
PostPosted: Sat Mar 28, 2015 4:33 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
lasaracina wrote:
In the following code you can see the 3 functions I use to define the headers, to create the table and to add rows to the created table.
But I cannot see the value of _OddAndEvenPagesHeaderFooter, I cannot see the PageSetup, I cannot see how the three methods are called in code.

An MDDDL file would allow me to see if there is a header in the document.
http://pdfsharp.net/wiki/MigraDocDDL.ashx

An SSCCE would allow me to debug the code.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
 Post subject: Re: Tables and headers
PostPosted: Tue Mar 31, 2015 2:53 pm 
Offline

Joined: Thu Mar 26, 2015 6:23 pm
Posts: 6
Solved.

I set the top margin uncorrectly. Setting the top margin at the end of the image in the Header it works!

Thanks anyway...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 372 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group