边界框中的itext多行文本 [英] itext multiline text in bounding box

查看:222
本文介绍了边界框中的itext多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道,如何在iText中在边界框中添加多行文字(指定坐标)。

Does anyone know, how to, in iText, add multiline text in bounding box (with coordinates specified).

我试过

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

但它不支持换行符。
我也试过

But it does not support newlines. I also tried

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

这支持换行但不对moveText作出反应,所以我不知道怎么把它放在给定位置或更好:边界框。

This supports newlines but does not react to moveText, so I don't know how to put it at given position or better: bounding box.

我怀疑块或PdfTemplate或者表可能有帮助,但我(还)知道如何把它放在一起。 TIA寻求帮助。

I suspect chunks or PdfTemplate or maybe table might help, but i don't (yet) know how to put it together. TIA for help.

推荐答案

试试这个:

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的参数是:

parameters of SetSimpleColumn are:


  1. 短语

  2. 左下角x(左)

  3. 左下角y(底部)

  4. 右上角x(右)

  5. 右上角y(上)

  6. 行高(领先)

  7. alignment。

  1. the phrase
  2. the lower left x corner (left)
  3. the lower left y corner (bottom)
  4. the upper right x corner (right)
  5. the upper right y corner (top)
  6. line height (leading)
  7. alignment.

这篇关于边界框中的itext多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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