I have a table, which contains several rows/cells. Each cell contains an image. When I add the image, I would like to add another image (with a transparent background) on the top of it. Can you please let me know how to do this?
Thank you for considering Aspose.
You can overlap the image using Watermark class of Aspose.Pdf. Watermarks are added as Floating boxes in which you need to provide the X and Y Cordinates of the image to be displayed, hence in your case you need to calculate your image sizes and by hit and trial you can add the overlapping images in the cells. Please refer to the following link to add watermarks.
Should you have any questions, feel free to ask.
You can also refer to Custom Positioning.
And how do I get the cordinates inside the table cell?
You will need to calculate them through trial and error method.
Ok, but how?
Just pick any value for X and Y and create the pdf. Look at the positioning and adjust the value of X and Y. Repeat this process until you have perfected the position.
Using custom positioning you can set the image position relative to another image. I think that is want you need.
I understand. How I am still not sure how I would get the coordinates from the image that in a cell. Even if I am able to figure it out, won't they change automatically if the PDF is open and I change the size? Can you guys maybe give me a working example that would illustrate how to place an image on the top of another when the parent image is being in a table cell?
Here is an example:
//create a pdf document
Pdf pdfDocument = new Pdf();
//create a new section and add it into the pdf document
Section sec1 = pdfDocument.Sections.Add();
//create a table and add it into the section
Table table1 = new Table();
table1.ColumnWidths = “200”;
//add a new row
Row row1 = table1.Rows.Add();
//add a new cell
Cell cell1 = row1.Cells.Add();
//add first image
Aspose.Pdf.Image img1 = new Aspose.Pdf.Image();
img1.ImageInfo.File = “c:/images/1.jpg”;
img1.ImageInfo.FixWidth = 200;
img1.ID = “Img1”;
//add another image
Aspose.Pdf.Image img2 = new Aspose.Pdf.Image();
img2.ImageInfo.File = “c:/images/2.jpg”;
img2.ImageInfo.FixWidth = 100;
//set position relative to the first image
img2.PositioningType = PositioningType.ParagraphRelative;
img2.ReferenceParagraphID = “Img1”;
img2.Top = 20;
img2.Left = 30;