Reputation: 1543
I want to create a table such as this with itext:
I tried to followed the solution here: Create a table in a generated PDF but unfortunately M
and F
column will not go beneath the Gender
column. Supposedly it should work like in the answer but it is not working. I'm not sure what is wrong. This is my code:
document.open();
PdfPTable table = new PdfPTable(5);
table.setWidths(new float[]{ 1f, 3f, 1f, 1f, 1f});
PdfPCell cell;
cell = new PdfPCell(new Phrase("Chapter"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Description"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(1);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Total"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("M");
table.addCell("F");
document.add(table);
document.close();
and this is my current output:
Can somebody help me with this?? Thanks in advance.
Upvotes: 0
Views: 50
Reputation: 1932
I understand it should be:
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(2);
table.addCell(cell);
since you want it to be two columns wide.
Upvotes: 2