Reputation: 2021
I want to create a receipt with iText. for example:
String1 = "Sale Amount"
String2 = "$2.00"
the purpose is how to justift the 2 Strings to the PDF Line and then I get:
------------------------------------
| Sale Amount $2.00 |
Sale Amount to the Left and $2.00 to the Right.
Upvotes: 0
Views: 104
Reputation: 77528
Please download chapter 2 of my book and start reading the section "SEPARATOR CHUNKS" on page 44. A separator chunk is a special Chunk
instance that acts the same way as "Glue" in Java. It is typically used to separate a title from a page number by a dotted line in a Table of Contents, but you can also use it without the dotted line to achieve the kind of alignment you need.
An alternative would be that you create a table with two columns and adapted cell borders. You'd then define the alignment of the cells in the first column as left aligned, and the alignment of the cells in the second column as right aligned. The disadvantage of this approach is that you need to define column widths (do you know what to expect?) and that you need to write more code. The advantage is that the content will wrap correctly if it doesn't fit on one line.
Upvotes: 1