Create your own implementation of a PdfPCellEvent
, for instance:
class ImageBackground implements PdfPCellEvent {
protected Image image;
public ImageBackground(Image image) {
this.image = image;
}
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
Image.scaleToFit(position.getWidth() , position.getHeight());
Image.setAbsolutePosition(position.getBottom(), position.getLeft());
cb.addImage(image);
}
}
Now when cell
is the PdfPCell
with the text and bgImage
the path to your image, do this:
Image image = Image.getInstance(bgImage);
cell.setCellEvent(new ImageBackground(image));
Now, you'll have an image that acts as the background of the cell.