边界框中的itext多行文本 [英] itext multiline text in bounding box
本文介绍了边界框中的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:
- 短语
- 左下角x(左)
- 左下角y(底部)
- 右上角x(右)
- 右上角y(上)
- 行高(领先)
- alignment。
- the phrase
- the lower left x corner (left)
- the lower left y corner (bottom)
- the upper right x corner (right)
- the upper right y corner (top)
- line height (leading)
- alignment.
这篇关于边界框中的itext多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文