Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to easily control spacing height between two paragraphs?

Tags:

itext

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?

like image 568
curious1 Avatar asked Oct 21 '25 13:10

curious1


1 Answers

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.

like image 126
Bruno Lowagie Avatar answered Oct 23 '25 07:10

Bruno Lowagie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!