iText placement of Phrase within ColumnText

前端 未结 1 1701
我寻月下人不归
我寻月下人不归 2021-01-07 13:01

So I\'m dealing with a situation where I have a Phrase added to a ColumnText object.

\"Text

1条回答
  •  清酒与你
    2021-01-07 14:06

    Please take a look at the ColumnTextAscender example:

    enter image description here

    In both cases, I have drawn a red rectangle:

    rect.setBorder(Rectangle.BOX);
    rect.setBorderWidth(0.5f);
    rect.setBorderColor(BaseColor.RED);
    PdfContentByte cb = writer.getDirectContent();
    cb.rectangle(rect);
    

    To the left, you see the text added the way you do. In this case, iText will add extra space commonly known as the leading. To the right, you see the text added the way you want to add it. In this case, we have told the ColumnText that it needs to use the Ascender value of the font:

    Phrase p = new Phrase("This text is added at the top of the column.");
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(rect);
    ct.setUseAscender(true);
    ct.addText(p);
    ct.go();
    

    Now the top of the text touches the border of the rectangle.

    0 讨论(0)
提交回复
热议问题