Search code examples
imagepdf-generationitextpdfptable

iText: Image in PdfpCell setAbsolutePosition does NOT work


I have a PdfPTable with 6 PdfPCell. I want to put an image in each cell at an absolute position. I just can get it to work, what am I doing wrong? As shown in the pic, the image always show on the to left (default) location.

laImage.scaleAbsolute(50, 50);  
laImage.setAbsolutePosition(0, 100);
laCell.addElement(laImage);

enter image description here


Solution

  • The setAbsolutePosition() method can be used to define the absolute position on a page (using the coordinates of the page) when adding an image to a document using document.add(). It is very surprising to discover that somebody would be using that method to define a relative position in a PdfPCell.

    Depending on what you really want, you could either change the padding of the PdfPCell (to create a distance between one or more of the cell borders and its content) or you could define a border for the Image object. This will introduce relative offsets.