How to easily control spacing height between two paragraphs?
13,370
The space between two lines of the same Paragraph
is called the leading. See Changing text line spacing
If you want to introduce extra spacing before or after a Paragraph
, you can use the setSpacingBefore()
or setSpacingAfter()
method. See itext spacingBefore property applied to Paragraph causes new page
For instance:
Paragraph paragraph1 = new Paragraph("First paragraph");
paragraph1.setSpacingAfter(72f);
document.add(paragraph1);
Paragraph paragraph2 = new Paragraph("Second paragraph");
document.add(paragraph2);
This puts 72 user units of extra white space between paragraph1
and paragraph2
. One user unit corresponds with one point, so by choosing 72, we've added an inch of white space.
Author by
curious1
Updated on June 04, 2022Comments
-
curious1 about 2 years
Currently, I am using
document.add( Chunk.NEWLINE );
after each paragraph to generate space between two paragraphs. What is the way to generate a spacing of any height I specify?
-
curious1 almost 8 yearsThanks for the info!
-
curious1 over 7 yearsBruno, do you happen to know of the solution to this display problem? stackoverflow.com/questions/39695541/…
-
Bruno Lowagie over 7 yearsI have commented on the answer @SamuelHuylebroeck and I leave it either to you to apply the tricks shown in the examples, or to Samuel to further elaborate on these examples in his answer.
-
chia yongkang over 4 yearsIf you use iText 7, you need to use setMarginBottom() instead of setSpacingAfter(). iText 7 syntax looks very much like HTML syntax