I have two numbers one above the other, but the first one must have an Strikethrough, I'm using a table and cell to put both numbers in the table, is there a way to make what I need?
2 Answers
Create a font with the style STRIKETHRU.
Font f = new Font(Font.FontFamily.HELVETICA, 12, Font.STRIKETHRU);

- 75,994
- 9
- 109
- 165

- 1,896
- 8
- 21
- 19
I am adding an extra answer for the sake of completeness.
Please take a look at the SimpleTable6 example:
In the first row, we strike through a number using a STRIKETHRU
font as explained by Paulo:
Font font = new Font(FontFamily.HELVETICA, 12f, Font.STRIKETHRU);
table.addCell(new Phrase("0123456789", font));
In this case, iText has made a couple of decisions for you: where do I put the line? How thick is the line?
If you want to make these decisions yourself, you can use the setUnderline()
method:
chunk1.setUnderline(1.5f, -1);
table.addCell(new Phrase(chunk1));
Chunk chunk2 = new Chunk("0123456789");
chunk2.setUnderline(1.5f, 3.5f);
table.addCell(new Phrase(chunk2));
If you pass a negative value for the y-offset parameter, the Chunk
will be underlined (see first column). You can also use this method to strike through text by passing a positive y-offset.
As you can see, we also defined the thickness of the line (1.5f
). There is another setUnderline()
method that also allows you to pass the following parameters:
- color - the color of the line or null to follow the text color
- thickness - the absolute thickness of the line
- thicknessMul - the thickness multiplication factor with the font size
- yPosition - the absolute y position relative to the baseline
- yPositionMul - the position multiplication factor with the font size
- cap - the end line cap. Allowed values are P
dfContentByte.LINE_CAP_BUTT
,PdfContentByte.LINE_CAP_ROUND
andPdfContentByte.LINE_CAP_PROJECTING_SQUARE
See http://api.itextpdf.com/itext/com/itextpdf/text/Chunk.html

- 75,994
- 9
- 109
- 165
-
Thanks for the example, both answers, yours and Paulo are the thing that I was looking for, thank you very much to both of you. – lschaves Feb 20 '15 at 20:17