Skip to main content
Skip table of contents

How to change the line spacing of text?

In my PDF the default space between the lines is slightly greater than I consider ideal.

I'm creating a PDF document consisting of text only, where all the text is the same point size and font family but each character could potentially be a different color. Everything seems to work fine, but the default space between the lines is slightly greater than I consider ideal. Is there a way to control this?

Posted on StackOverflow on Feb 16, 2014 by user2079230

According to the PDF specification, the distance between the baseline of two lines is called the leading. In iText, the default leading is 1.5 times the size of the font. For instance: the default font size is 12 pt, hence the default leading is 18.

In iText 7 you can change the leading of a Paragraph using one of these methods:

paragraph.setFixedLeading(leadingValue);

or

paragraph.setMultipliedLeading(leadingValue);

The first method sets the fixed leading: if you want a leading of 15 no matter which font size is used, you should use first method with argument 15. The second method sets a factor: for instance if you want the leading to be twice the font size, you should use the second method with argument = 2. In this case, the leading for a paragraph with font size 12 will be 24, for a font size 10, it will be 20, and so on. You cannot combine fixed and multiplied leading. You can use only one of them.

Click How to change the line spacing of text? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.