berimbolo
berimbolo

Reputation: 3829

Itext 7 - Undesired bottom margin when text is placed a in paragraph

I am using iText 7 and placing paragraphs into a div, I have set the setMultipliedLeading(1.0F) value but I get a margin underneath the paragraphs that I do not want. The paragraphs in question are the red ones labelled Para 1 and Para 2, the other paragraphs have divs to create additional space (as well exhibiting the same bottom margin issue) but I would still like to remove the extra bit of space I do not want for these as well (as demonstrated by the red paragraphs).

It looks like older versions of iText supported a spacing before and after a paragraph. Is there a way to achieve this with iText 7?

I have attached an image that shows this extra spacing, what you can see is just paragraphs with their background colour set. I want to remove the bottom margin and have the coloured sections sit flush with each other.

enter image description here

I have tried setting the bottom margin of the paragraphs like this label.setMarginBottom(0.0F); (label is a Paragraph) but the margin is still present.

Upvotes: 2

Views: 4302

Answers (1)

berimbolo
berimbolo

Reputation: 3829

With thanks to Bruno for pointing me in the right direction, it seems that when you add text to a paragraph in iText7 it will automatically add a top and bottom margin.

This is very easy to remove:

private Paragraph createFieldLabel(final String text)
{
    final Paragraph label = new Paragraph(text);        
    label.setMultipliedLeading(1.0F);
    label.setFontSize(12.0F);
    label.setMarginBottom(0.0F);
    label.setMarginTop(0.0F);

    return label;
}

Upvotes: 4

Related Questions