4

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
curious1
  • 14,155
  • 37
  • 130
  • 231

1 Answers1

13

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.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thanks for the info! – curious1 Sep 26 '16 at 02:11
  • Bruno, do you happen to know of the solution to this display problem? http://stackoverflow.com/questions/39695541/strange-display-of-a-table-of-radio-buttons – curious1 Sep 26 '16 at 15:14
  • I 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. – Bruno Lowagie Sep 26 '16 at 16:45
  • 6
    If you use iText 7, you need to use setMarginBottom() instead of setSpacingAfter(). iText 7 syntax looks very much like HTML syntax – chia yongkang Nov 30 '19 at 03:56