Your question sounds wrong. It's as if you want to add an image watermark to a document, which is adequately explained in many other questions such as Set a fix background image for all my pages in PDF iText ASP C# and How can I add an image to all pages of my PDF? (These answers are about C# questions, but the official web site has many watermark and page event examples.)
Just like madhesh, you confuse the StackOverflow readers, even after you've read my answer to the question How to add text to an image? where I wrote:
This is a good example of a question that is phrased in a way that nobody can answer it correctly. After a lot of back and forth comments, it was finally clear that the OP wanted to add a text watermark to an image. Badly phrase questions can be very frustrating. Please take that in consideration when asking a question. In this case, I gave several wrong answers before it became clear what was actually asked.
You want to add a PdfPTable
to an Image
and your knowledge is insufficient to understand and adapt the examples provided with the answers to questions such as How to add text to an image? and Draw Lines on Image in PDF using ItextSharp.
What you're asking is extremely simple though.
The getWatermarkedImage()
method that you mention looks like this:
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
template.saveState();
template.setColorStroke(BaseColor.GREEN);
template.setLineWidth(3);
template.moveTo(width * .25f, height * .25f);
template.lineTo(width * .75f, height * .75f);
template.moveTo(width * .25f, height * .75f);
template.lineTo(width * .25f, height * .25f);
template.stroke();
template.setColorStroke(BaseColor.WHITE);
template.ellipse(0, 0, width, height);
template.stroke();
template.restoreState();
return Image.getInstance(template);
}
This is the example taken from the answer to the question How to draw lines on an image?
You don't want to draw lines, so you can remove all the code that draws lines:
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
// removed the code that draws lines
return Image.getInstance(template);
}
Instead of lines, you want to draw a PdfPTable
, so we add some code where it says // removed the code that draws lines
. As documented, adding a table at an absolute position is done with the writeSelectedRows()
method:
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(width);
table.getDefaultCell().setBorderColor(BaseColor.Yellow);
table.addCell("Test1");
table.addCell("Test2");
table.addCell("Test3");
table.addCell("Test4");
table.writeSelectedRows(0, -1, 0, height, template);
return Image.getInstance(template);
}
I adapted one of the many examples in the official documentation (see WatermarkedImages5), and this is the result:

All the functionality you needed to achieve this was available in the documentation. Please read that documentation before you post another question.