-1

I am using XMLWorker 5.5.3 and itextpdf 5.5.3 to convert html to pdf. my html contain table with cells that conatin images. i.e. part of my code :

enter image description here

my problem is that some cells add padding > 0 so the td that contain the image is bigger than it should be. Is there a way to define style for images so the will not have padding and margin ? I am looking at css Demo of Itextpdf and not finding a solution , any help/trick /ideas will help . thanks Tami

tamih
  • 93
  • 1
  • 15

1 Answers1

0

I found a solution: when I create the table I define columns width :

 PdfPTable table = new PdfPTable(vColWidth.length);
 table.setWidthPercentage(100);
 table.setWidths(vColWidth);

when creating the Image object I define :

RegularImg = Image.getInstance(imgsrc); 
RegularImg.setSpacingAfter(0);
RegularImg.setSpacingBefore(0);

when defining the td :

cell = new PdfPCell(RegularImg);
if(colSpan!="") 
    cell.setColspan(Integer.parseInt(colSpan));
if(rowSpan!= "") 
    cell.setRowspan(Integer.parseInt(rowSpan));
if(cellHight!="") 
    cell.setFixedHeight(Float.parseFloat(cellHight));

table.addCell(cell);

this solutions works o.k. if the table is not so big or complicated with the colSpan , rowSpan . In complicated cases I advise people to convert the table of pictures as a Canvas , not using a table. just place each Image in the specific place in the doc . (the performance are much faster.

tamih
  • 93
  • 1
  • 15