java - iText combining rowspan and colspan - PDFPTable -


working on calendar projcet , using itext generate pdf print appointments. can plot cell colspan, , cell rowspan, can't combine it. table has width of 4 cells. want achieve this:

(a)(b)(c)(c)

(d)(e)(c)(c)

so (1,1), (1,2) , (2,1) (2,2) regular cells. there should cell in (1,3) covering (1,3) (1,4) (2,3) , (2,4) having colspan of 2 , rowspan of 2.

current code:

pdfptable table = new pdfptable(4);

pdfpcell cell = new pdfpcell(new phrase(" 1,1 "));

table.addcell(cell);

cell = new pdfpcell(new phrase(" 1,2 "));

table.addcell(cell);

pdfpcell cell23 = new pdfpcell(new phrase("multi 1,3 , 1,4"));

cell23.setcolspan(2);

cell23.setrowspan(2);

table.addcell(cell23);

cell = new pdfpcell(new phrase(" 2,1 "));

table.addcell(cell);

cell = new pdfpcell(new phrase(" 2,2 "));

table.addcell(cell);

// 2,3 , 2,4 should filled because 1,3 has rowspan 2 , colspan 2.

//table.completerow(); //no effect

however generates error:

exceptionconverter: java.io.ioexception: document has no pages.

if don't start creating second row, plots fine ( 1 row, , cell on (1,3) has colspan of 2. since there no second row, rowspan(2) has no effect. appreciated. thanks

at first sight, i'd say: "document has no pages" exception because you're not adding content document. don't see:

document.add(table); 

anywhere in code snippet.

i have copy/pasted code full example , posted full example here: colspanrowspan. resulting pdf looks this:

enter image description here

this seems desired behavior. can think of 2 differences: (1) you're forgetting add actual table (which initial answer), or (2) using mighty old version of itext in rowspan wasn't supported.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -