java - adding row to a table in PDF using iText -
pdfptable table = new pdfptable(8); pdfpcell cell; cell = new pdfpcell(); cell.setrowspan(2); table.addcell(cell); for(int aw=0;aw<8;aw++){ table.addcell("hi"); }
what getting in code table 8 columns , 3 rows. should 2 2 rows. , 1st column in 3 rows empty, remaining cells filled hi..
try this:
pdfptable table = new pdfptable(8); pdfpcell cell; for(int aw=0;aw<8;aw++) { cell = new pdfpcell(new paragraph("hi")); table.addcell(cell ); }
edit:
// step 1 document document = new document(); // step 2 pdfwriter.getinstance(document, new fileoutputstream(filename)); // step 3 document.open(); // step 4 pdfptable table = new pdfptable(8); for(int aw=0;aw<16 ; aw++){ table.addcell("hi"); } // step 5 document.add(table); // step 6 document.close();
see simpletable total sample code , resulting pdf:
as can see in screen shot, table has 8 columns , 2 rows (as expected).
reading original question, see first column has cell colspan 2. it's little alter take account:
pdfptable table = new pdfptable(8); pdfpcell cell = new pdfpcell(new phrase("hi")); cell.setrowspan(2); table.addcell(cell); for(int aw = 0; aw < 14; aw++){ table.addcell("hi"); }
now result looks this:
again 8 columns , 2 rows, cell in first column spans 2 rows.
java itext
No comments:
Post a Comment