PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 7:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat Feb 28, 2015 4:17 pm 
Offline

Joined: Sat Feb 28, 2015 3:39 pm
Posts: 4
I have a couple of paragraphs that are in a text frame. This text comes after a table that may span over multiple pages and it doesn't matter how much of the last page is filled, the text frame is suppose to be at the bottom. This code pretty much gave me what I needed, but if the table goes to the bottom of the page, the text in the text frame and the text in the table overlap.
Code:
var tf = section.AddTextFrame();
tf.Width = "190mm";
tf.Height = "55mm";
tf.RelativeHorizontal = RelativeHorizontal.Page;
tf.RelativeVertical = RelativeVertical.Margin;
tf.Left = ShapePosition.Center;
tf.Top = ShapePosition.Bottom;

I don't mind to even put this text in the footer, but only the footer of the last page, which I have no clue how to do.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 8:10 am 
Offline
PDFsharp Expert
User avatar

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

You can give that textframe an absolute position, placing it in the footer area, thus preventing the overlap between table and textframe.

Using "RelativeVertical.Page" and "ShapePosition.Top" with an appropriate offset should do the trick.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 8:17 am 
Offline

Joined: Sat Feb 28, 2015 3:39 pm
Posts: 4
Yes, but how do I put the textframe in the footer of the last page only?

And if I put the textframe in the footer and the frame pushes the end of the table in the next page, I won't get what I want...

EDIT:

Actually I think that the footer is a bad idea because of the case I mentioned.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 8:52 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
I did not suggest to put the textframe into the footer, I suggested to place it in the footer area to prevent overlap.
You add it to the body of the document after the table, but place it below the bottom margin.

If the textframe is higher than the bottom margin or should not be in the footer area: you can add an empty row at the end of the table and tell MigraDoc to keep the empty row together with the previous row. This will ensure that the body on the last page will have a free area at the bottom. This is another way to prevent overlapping between visible table rows and textframe.

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 9:35 am 
Offline

Joined: Sat Feb 28, 2015 3:39 pm
Posts: 4
The text is a bit larger than thee footer margins so I can't put it the footer area.

I tried to add the empty row:
Code:
var lastRow = table.AddRow();
lastRow.KeepWith = 1;


but this gives me a null reference exception when the document is rendered. And the text frame offset is set using the top margin right?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 1:56 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
The KeepWith must be set on the first row of the block. KeepWith=1 will keep two rows together.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 6:01 pm 
Offline

Joined: Sat Feb 28, 2015 3:39 pm
Posts: 4
This is how my code looks:

Code:
 var i = 1;
    foreach (var tmp in list)
    {
        var row = table.AddRow();
        if (i == 1)
        {
            row.KeepWith = 1;
        }
        // the cells are filled right after this
    }
    var lastRow = table.AddRow();
    lastRow.Height = "55mm"; // the textframe is 47mm high so this row, if overlapped with the text frame will make sure that the text frame is on the last page
    lastRow.Cells[0].AddParagraph();
    var tf = section.AddTextFrame();
    tf.Width = "190mm";
    tf.RelativeVertical = RelativeVertical.Page;
    tf.Top = ShapePosition.Top;
    tf.MarginTop = "230mm";


This looks OK to me, but apparently I got some of the logic of how MigraDoc works wrong since it still doesn't look the way I want it to.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 03, 2015 8:57 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Your code sets KeepWith=1 for all rows.

I'd use code like this before adding the dummy row:
Code:
table.Rows[table.Rows.Count - 1].KeepWith = 1;

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 51 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group