I have a requirement to add images in an iText PDF table, but the position of cells (consisting of images) will depend on indexes (row and column number) given by the user. This table could also have empty cells in between if no index for any image is given.
How to add a cell in itext pdf at random position?
I looked out for this at various forums, not successful. I would really appriciate the help.
There is no API in iText's
Table
class to add a cell to an arbitrary position. The reasoning behind such a decision lies in iText'sTable
architecture: if a table has not been constructed yet (i.e. it's unknown whether there will be some cells with a rowpan and/or a colpan greater than 1), it's not feasible for iText to know whether it could place a cell at some custom position.However, the good news is that all the layout-related code is triggered only after the table is added to the document. So, one can always do the following:
Cell
objectsCell
object as requestedIn the snippet above I will show, hot to add some diagonal content to the table after the cells have been added to it. The same approach could be followed for images.
The resultant PDF looks as follows: