user3633028 user3633028 - 1 month ago 7x
Java Question

java code to reduce space between lines

I am creating a pdf with some content in it. My requirement is to reduce the space between lines while creating the pdf so that more number of lines fit in single page.How can i reduce the space between lines,please suggest.

Document document = null;
PdfWriter.getInstance(document,new FileOutputStream("Paragraph2.pdf"));;

Font font = new Font(Font.FontFamily.COURIER,12);

//code to get the content to show in the document

for (final String line : documentines.getDocumentLine())
document.add(new Paragraph(line,font));


The space between two lines is called the leading.

You change it with the setleading() method.

For instance:


Note: by default, iText takes 1.5 times the font size. If the font size is 12, the leading will be 18 by default.

You can also set the leading in the constructor:

document.add(new Paragraph(15, line, font));