java - iText formatting tables -


i'm generating pdf document (for have seen before, yes still) using itext library. compliments bruno lowagie; i've found great api!

however, part of task format phrases. used nested pdfptable format data, i'm getting bizarre spacing issues. here example of problem i'm facing:

enter image description here

as can see, rows couple of phrases in them tend have huge gaps in between them. can understand why happening; rows above stretching table. there way make table big needs be, , no larger?

code

generating prices collection

i'm creating prices snippet:

 paragraph pricepara = new paragraph();  pricepara.add(price);  pricepara.add(generatebreakline());  pricepara.add(time);  pricepara.add(generatebreakline());  allprices.add(pricepara); 

where generatebreakline() returns empty paragraph object.

adding them cell

i add them cell following snippet:

 // 5 amount of prices can fit on 1 line.  pdfptable pricescellvalue = new pdfptable(elements.size() > 5 ? 5 : elements.size());     // make appear prices horizontal, opposed in table.     pricescellvalue.getdefaultcell().setborder(pdfpcell.no_border);      // cycle through each price. add cell. add cell table.     (com.lowagie.text.element elem : elements) {         pdfpcell cell = new pdfpcell((paragraph) elem);         cell.setborder(pdfpcell.no_border);         cell.setpadding(2);         pricescellvalue.addcell(cell);     }     return pricescellvalue;  

the above snippet, believe, can make sure table wide needs be, opposed filling space around it. how go doing that?

solved

found simple way of fixing it. in stead of changing amount of columns based on number of prices, make sure column number 5, , append empty cells on:

  if(elements.size() < 5)     {         int diff = 5 - elements.size();          for(int x = 0; x < diff; x++)         {             pricescellvalue.addcell(new paragraph(" "));         }     } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -