Good day, I am currently facing a text alignment problem with itext 7 you will see I am creating a kind of invoice with text and amounts but currently I have managed to align the entire paragraph in one direction either left or right as you see in the following image:
As you can see, all the text is on the right but I need to separate it, I need the text to be on the left and the amounts on the right, always on the same line of course, as shown in the following image:
But I haven't been able to do this with itext 7 , this is the code to create the paragraphs:
detalle = "[C]" + gTipoPago + "\n" +
"[R]================================\n" +
"[L]" + "Venta(+) $ " + String.format("%.2f", monto) + "\n" +
"[R]" + "Devolución(-) $ " + String.format("%.2f", montoDevolucion) + "\n" +
"[R]" + "Encontrado(-) $ " + String.format("%.2f", montoFisico) + "\n" +
"[R]" + "Monto diferencia(=) $ " + String.format("%.2f", montoDiferencia) + "\n" +
"[R]================================\n";
arrayList.add(detalle);
Since they are dynamic database data, I make a query and add them to a arraylist
and maybe that is the problem that the data is dynamic or I don't know...
Then in itext 7 I create the paragraph and command to call that arraylist
:
Paragraph gastos = new Paragraph(arrayList2.toString().replace("[", "").replace("]", "").replace(",", "") + "\n").setTextAlignment(TextAlignment.LEFT);
In this case, as you can see itext 7 , nothing more than the option to align to the left, to the right or to the center and as in an array, the one I get, well, the entire array is aligned to the position that I give it in this caseTextAlignment.LEFT
In conclusion, I am looking for a way to separate the text from the amounts to align them in the position you want, always on the same line of course.
And well that would be all if you need more explanation or more code or whatever let me know in advance thank you very much!
I suggest you use a table to add the texts to the left and the prices to the right like this:
ElementItext element = new ElementItext (); element.setAlignment(Element.ALIGN_LEFT);
//You decide where it lines up