iTextSharp table.SpacingBefore not working when the table is the first item

itext, spacing

Solution

Please take a look at the following screen shot:

The file spacing1.pdf (shown underneath the other ones) is created using the way you describe. By design the "spacing before" is ignored, because the "spacing" functionality allows you to create some space between different elements on the page. If there is no other element, no spacing is added. This is the case in your example: the table is the first element, so there's no need to add "spacing before". For the same reason "spacing after" is ignored when the table is the final element on the page.

The file spacing2.pdf (shown in the middle) is created by adding a `Paragraph` object before adding the table. As you can see, extra spacing is added between the `Paragraph` and the `PdfPTable`. You say there isn't. In my case, the screen shot makes it very clear there is. Which version of iTextSharp are you using?

I think your analysis of your requirement is wrong. You don't want spacing before or after. You want spacing. That's what I did in spacing3.pdf (shown on the right, on top of the other windows).

I introduced this spacing by adding the following `Paragraph` before adding the table:

document.Add(new Paragraph(100, "\u00a0"));

The `100` in this Paragraph is the leading. It defines the amount of space that is added. The `"\u00a0"` is a string with a single "non-breaking space" character.

I think that is what you're asking for. That's something different than "spacing before".

Problem

I am trying to put some space before a table in my PDF file using table.SpacingBefore, but it doesn't work. I have found iTextSharp table.SpacingBefore not working which is exactly the same problem but the solution doesn't seem to be working. Here's a bit of my code: ``` header.SpacingBefore = 150f; Paragraph paragraph = new Paragraph(); paragraph.Leading = 0f; doc1.Add(paragraph); doc1.Add(header); ``` The result is: Adding a non-empty paragraph ``` Paragraph paragraph = new Paragraph(" TEXT "); ``` produces this:

Original source

Related problems