What is the best way to create a row of text that will have two elements aligned to an imaginary line? Like this (four rows given to illustrate the point better):
1. some random text
34. some more random text
764. here's even more random text
4594. it just never ends
Imaginary line would go trough the dots, or the space after them. The numbers have right alignment, and the text has left alignment.
I do not want to use a list because elements may not be in order, and it has certain limitation with setting the line spacing.
You can use a PdfPTable with 2 columns, the first right aligned and the last left aligned. Then set the designer padding on the cells content. For example:
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);
You can see that cell border are disabled (disableBorderSide
method).
You can also adjust the minimum height of cells using setMinimumHeight
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With