在单行中以itext对齐文本



创建一排文本的最佳方法是什么?这样(给出四行以更好地说明点):

   1. some random text
  34. some more random text
 764. here's even more random text
4594. it just never ends

虚线将陷入圆点或之后的空间。这些数字具有正确的对齐方式,并且文本已剩下对齐。

我不想使用列表,因为元素可能没有秩序,并且在设置行间距方面具有一定的限制。

您可以使用具有2列的PDFPTPT,第一个右对齐,最后一个左对齐。然后将设计器填充在单元格内容上。例如:

PdfPTable tbl = new PdfPTable(2);
PdfPCell cell = new PdfPCell(new Phrase("1."));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("some random text"));
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("34."));
cell.disableBorderSide(Rectangle.BOX);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
tbl.addCell(cell);
cell = new PdfPCell(new Phrase("some more random text"));
cell.disableBorderSide(Rectangle.BOX);
tbl.addCell(cell);

您可以看到禁用单元边框(disableBorderSide方法)。您还可以使用setMinimumHeight方法调整单元格的最小高度。

最新更新