PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Oct 19, 2019 9:13 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Fri Nov 05, 2010 9:40 am 
Offline

Joined: Mon Nov 01, 2010 2:23 pm
Posts: 17
Location: Prague, Czech Republic
Hi,

in my document I want to separate tables by a specific amount of vertical space (say 5 mm). How can I do that? I tried to add an empty paragraph with SpaceAfter set to the desired value but this ends up being different when I export the document to PDF and RTF - in the PDF file the space after the table is much bigger than in the RTF. Is there any other way to separate the tables?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 05, 2010 2:43 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I have no experience of RTF output, but for PDFs i always use another table to create "spaces" - I have a little function:

Code:
public Table BuildSpacerTable(Unit height)
        {
            MigraDoc.DocumentObjectModel.Tables.Table _table = new Table();
            _table.AddColumn(Page.Width - (LeftMargin + RightMargin));
            try
            {
                Row _row = _table.AddRow();
                _row.Height = height;
                _row.HeightRule = RowHeightRule.Exactly;
                Cell _cell = _row.Cells[0];
                _cell.Borders.Width = 0;
                YourDocumentObjectHere.LastSection.Add(_table);
            }
            catch
            {
            }
            return _table;
        }

This then allows me to add "spaces" with the height set by the MigraDoc.DocumentObjectModel.Unit i pass into the function.

Hope ths helps.

Mike


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 11, 2011 9:55 am 
Offline

Joined: Mon Nov 01, 2010 2:23 pm
Posts: 17
Location: Prague, Czech Republic
I finally found the problem. When I add an empty paragraph, it has a predefined height (determined by the font height). In order for it to have exactly the height I specify in the SpaceAfter property, its content height must be zero. I achieve that by setting the LineSpacingRule to Exactly.

Code:
MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
paragraph.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
paragraph.Format.LineSpacing = MigraDoc.DocumentObjectModel.Unit.FromMillimeter( 0.0 );


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 16, 2011 11:31 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
Just a suggestion. Tables are really expensive in MigraDoc. Adding an empty spacer paragraph like the OP mentioned is a far less expensive way to do it.

But what's unfortunate is that if the table just fits on the page, the next page will have extra space at the top. It would be best if there were a "SpaceAfter" property like in paragraphs.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 17, 2011 7:51 am 
Offline

Joined: Mon Nov 01, 2010 2:23 pm
Posts: 17
Location: Prague, Czech Republic
jeffhare wrote:
But what's unfortunate is that if the table just fits on the page, the next page will have extra space at the top. It would be best if there were a "SpaceAfter" property like in paragraphs.

That's exactly my thought, but the table doesn't seem to behave this way.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 8:17 am 
Offline

Joined: Wed Aug 08, 2018 8:07 am
Posts: 4
Location: Germany
This problem still remains for exact the same reason with an addition.
Adding a paragraph between tables would add an unwanted free space at the next page if the table exactly fits the page.
You also have to check, if it is not the last table. In this case you'll get a blank page.

A simple Table.SpaceAfter that will be ignored if the table fits the page would solve the problem.

Or is there a better solution?

_________________
Shine On, Frank


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 8:25 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2980
Location: Cologne, Germany
froes wrote:
Adding a paragraph between tables would add an unwanted free space at the next page if the table exactly fits the page.
Then use SpaceBefore instead of SpaceAfter and wait for a future release of MigraDoc that ignores SpaceBefore at the top of a page when creating PDF (AFAIK Word ignores it automatically when dealing with RTF). We changed this recently, but I think it is not yet included with 1.50 RC2a.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 9:15 am 
Offline

Joined: Wed Aug 08, 2018 8:07 am
Posts: 4
Location: Germany
Table has nor SpaceBefore not SpaceAfter.

_________________
Shine On, Frank


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 9:41 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2980
Location: Cologne, Germany
froes wrote:
Table has nor SpaceBefore not SpaceAfter.
The paragraph added to separate two tables has.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 10:19 am 
Offline

Joined: Wed Aug 08, 2018 8:07 am
Posts: 4
Location: Germany
So this should do the Job?
Code:
private void addSpace(Section sec, Unit height)
{
   Paragraph p = sec.AddParagraph();
   p.Format.LineSpacingRule = LineSpacingRule.Exactly;
   p.Format.LineSpacing = "0mm";
   p.Format.SpaceBefore = height;
}


I also checked another idea. I added a fat border to the botton of each cell of the last row of each intermediate table. As the border is white it works.

_________________
Shine On, Frank


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 11:01 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2980
Location: Cologne, Germany
You can also add an empty row without any contents and any borders at the end of the table. You can set the height of that row as needed.
Set KeepWithNext=1 on the row before the dummy row to prevent pagebreaks before the dummy row.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 12:03 pm 
Offline

Joined: Wed Aug 08, 2018 8:07 am
Posts: 4
Location: Germany
Danke Thomas! :wink:

_________________
Shine On, Frank


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 198 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