java - unable to calculate itext PdfPTable/PdfPCell height properly -


i'm facing problem while trying generate pdfptable , calculate height before adding document. method calculateheights of pdfptable returned height lot greater height of page (while table 1/4 of page's height), wrote method calculate height:

protected float getverticalsize() throws documentexception, parseexception, ioexception {     float overallheight=0.0f;     for(pdfprow currow : this.getpdfobject().getrows()) {         float maxheight = 0.0f;         for(pdfpcell curcell : currow.getcells()) {             if(curcell.getheight()>maxheight) maxheight=curcell.getheight();         }         overallheight+=maxheight;     }     return overallheight; } 

where getpdfobject method returns pdfptable object.
using debugger i've discovered lly , ury coordinate difference (and height) of cell's rectangle bigger looks after adding table document (for example, 1 cell 20 , other 38 height while same on page). there nothing in cell except paragraph chunk in it:

font f = getfont();         if (f != null) {             int[] color = gettextcolor();             if(color != null) f.setcolor(color[0],color[1],color[2]);             ch = new chunk(celltext, f);             par = new paragraph(ch);         } cell = new pdfpcell(par); cell.sethorizontalalignment(gethorizontaltextalignment()); cell.setverticalalignment(getverticaltextalignment()); 

a table has cell added , setwidthpercentage attribute set float. doing wrong? why cell's proportions different see after generating pdf? maybe i'm calculating height wrong? isn't height of cell on pdf page should strictly difference between lly , ury coordinates
sorry haven't shown exact code, because pdf being generated of xml using lots of intermediate steps , objects , not useful "as is" guess...
in advance!

the height of table added page available width 400 different height of table added page available width 1000. there no way can measure height correctly until width defined.

defining width can done adding table document. once table rendered, total height known.

if want know height in advance, need define width in advance. instance using:

table.settotalwidth(400); table.setlockedwidth(true); 

this explained in tableheight example. in table_height.pdf, see itext returns height of 0 before adding table , height of 48 after adding table. itext returns 0 because there no way determine actual height.

we take same table , define total width of 50 (which smaller original 80% of available width on page). when calculate height of table same contents, itext returns 192 instead of 48. when @ table on page, cause of difference in height obvious.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -