PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

How can I add a spacing after a table?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=1408
Page 1 of 1

Author:  crypto_rsa [ Fri Nov 05, 2010 9:40 am ]
Post subject:  How can I add a spacing after a table?

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?

Author:  mikesowerbutts [ Fri Nov 05, 2010 2:43 pm ]
Post subject:  Re: How can I add a spacing after a table?

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

Author:  crypto_rsa [ Fri Mar 11, 2011 9:55 am ]
Post subject:  Re: How can I add a spacing after a table?

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 );

Author:  jeffhare [ Wed Mar 16, 2011 11:31 pm ]
Post subject:  Re: How can I add a spacing after a table?

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.

Author:  crypto_rsa [ Thu Mar 17, 2011 7:51 am ]
Post subject:  Re: How can I add a spacing after a table?

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.

Author:  froes [ Wed Aug 08, 2018 8:17 am ]
Post subject:  Re: How can I add a spacing after a table?

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?

Author:  Thomas Hoevel [ Wed Aug 08, 2018 8:25 am ]
Post subject:  Re: How can I add a spacing after a table?

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.

Author:  froes [ Wed Aug 08, 2018 9:15 am ]
Post subject:  Re: How can I add a spacing after a table?

Table has nor SpaceBefore not SpaceAfter.

Author:  Thomas Hoevel [ Wed Aug 08, 2018 9:41 am ]
Post subject:  Re: How can I add a spacing after a table?

froes wrote:
Table has nor SpaceBefore not SpaceAfter.
The paragraph added to separate two tables has.

Author:  froes [ Wed Aug 08, 2018 10:19 am ]
Post subject:  Re: How can I add a spacing after a table?

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.

Author:  Thomas Hoevel [ Wed Aug 08, 2018 11:01 am ]
Post subject:  Re: How can I add a spacing after a table?

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.

Author:  froes [ Wed Aug 08, 2018 12:03 pm ]
Post subject:  Re: How can I add a spacing after a table?

Danke Thomas! :wink:

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/