边界框中的itext多行文本
有没有人知道,如何在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的参数是:
- 词组
- 左下角x(左)
- 左下角y(底部)
- 右上角x(右)
- 右上角y(上)
- 线高(领先)
- 对准。
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