谁知道,如何在Itext中添加多行文本在边界框中(指定的坐标)。

我试过了

cb.showTextAligned(
    PdfContentByte.ALIGN_LEFT,
    text,
    bounds.getLeft(),
    TOTAL_HEIGHT-bounds.getTop(),
    0 );

但是它不支持新线。我也尝试了

PdfContentByte cb = writer.getDirectContent();
cb.moveText(300,400);
document.add(new Paragraph("TEST paragraph\nNewline"));

这支持了新线,但对MoveText没有反应,因此我不知道如何将其放在给定的位置或更好的位置:边界框。

我怀疑块或pdftemplate或表格可能会有所帮助,但我(但我还不知道如何将其放在一起)。 tia寻求帮助。

有帮助吗?

解决方案

尝试这个:

ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("TEST paragraph\nAfter Newline");
ct.setSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT);
ct.go();

setSimplecolumn的参数为:

  1. 词组
  2. 左下X角(左)
  3. 左下角(底部)
  4. 右上x角(右)
  5. 右上Y角(顶部)
  6. 线高(领先)
  7. 结盟。

其他提示

ColumnText ct = new ColumnText(content);
ct.setSimpleColumn(
    new Phrase("Very Long Text"),
    left=20, bottom=100, right=500, top=500,
    fontSize=18, Element.ALIGN_JUSTIFIED);
ct.go(); // for drawing
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top