如何用虚线强调文本



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

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

我试图玩: pnote.setExtraparagraphSpace(-15);但这搞砸了下一段。我也尝试了:Itext定位文本而且工作正常,但只有固定我的PDF尺寸。所以不要解决我的问题。

当您需要虚线时,使用带有点的字符串不是一个好主意。最好使用使用DottedLineSeparator类创建的虚线。例如,请参见UnderlineWithDottedLine示例。

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

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

最新更新