I need to draw a table like this.
---------------
| A | C |
|------| |
| B | |
---------------
The following code does not work. It creates a table with a single row, without drawing the 'C' cell:
PdfPTable table = new PdfPTable(2);
table.addCell("A");
table.addCell("B");
PdfPCell cell = new PdfPCell(new Phrase("C"));
cell.setRowspan(2);
table.addCell(cell);
Drawing the opposite table (with the rowspanning cell on the left) works just fine.
I have noticed a similar question here, but the context is different (I am not working on an international app) so I think I can rephrase the question again.
Tables are always drawn left to right, top to bottom, so you need to add A
, then C
and then finally B
.
PdfPTable table = new PdfPTable(2);
table.addCell("A");
PdfPCell cell = new PdfPCell(new Phrase("C"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("B");
iText requires that all cells in a table are accounted for. If any cells are missing it skips that entire row. Your original code added A
to R1C1, then B
to R1C2, then created a new row and added a single cell to it, which, since it was a widow got trimmed off.
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