How to underline text with a dotted line?

这一生的挚爱 提交于 2019-12-24 08:49:44

问题


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 mess up the next paragraphs. I tried too with this: itext positioning text absolutely and works fine but only if my pdf size is fixed. So don't solve my problem.


回答1:


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();
dottedline.setOffset(-2);
dottedline.setGap(2f);
p.add(dottedline);
document.add(p);

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).



来源:https://stackoverflow.com/questions/22382717/how-to-underline-text-with-a-dotted-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!