如何用虚线在文本下划线? [英] How to underline text with a dotted line?

查看:79
本文介绍了如何用虚线在文本下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要合并2个段落,第一个是点的序列,第二个是我要在点上写的文本:

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

我试图玩: pnote.setExtraParagraphSpace(-15); 但是,这弄乱了下几段.我也尝试过这样的方法:完全使用itext定位文本 并且可以正常工作,但前提是我的pdf大小是固定的.所以不要解决我的问题.

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.

推荐答案

当您需要虚线时,最好不要在字符串上使用带点的字符串.最好使用通过DottedLineSeparator类创建的虚线.例如,请参见 UnderlineWithDottedLine 示例.

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

在此示例中(有关结果,请参见 underline_dotted.pdf ),我在段落的基线下添加2点线(使用setOffset()方法),并定义点之间的2点间距(使用setGap()方法).

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

这篇关于如何用虚线在文本下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆