Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

I need to merge 2 paragraphs, the first is a sequence of dots, and the second is the text that I want write on dots:

Paragraph pdots1 = new Paragraph(
    "..................................................", font10);
Paragraph  pnote= new Paragraph("Some text on the dots", font10);

I tried to play with: pnote.setExtraParagraphSpace(-15); But this messes up the next paragraphs.

Posted on StackOverflow on Mar 13, 2014 by Accollativo

It's not a good idea to use a String with dots when you need a dotted line. It's better to use a dotted line created using the DottedLineSeparator class. See for instance the UnderlineWithDottedLine example.

Paragraph p = new Paragraph("This line will be underlined with a dotted line.");
DottedLineSeparator dottedline = new DottedLineSeparator();

In this example (see underline_dotted.pdf for the result), I add the line 2 points under the baseline of the paragraph (using the setOffset() method) and I define a gap of 2 points between the dots (using the setGap() method).