We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Placing image in specific cell of a specific table

Hi Team
I have a requirement of placing an image in a specific cell of a table.
Scenario: there is a specific text “ABC” in a cell of a table. in the next three cells of that table i need to place an image in each and date in last cell of same row.
Ex: “ABC”| {Image1}|{Image2}|{“myDate”}.

Currently, i’m capturing the locations for the text “ABC” and trying to place image next to it.
Issue: this works for few documents but few documents/tables have different padding/cell sizes thus causing second image to be split b/w two cells.

Can you help me with finding a better solution to place images + date properly within the cells irrespective of the cells size/padding?
I don’t know the table name and there could be multiple table on the doc.
Quick help is appreciated. My firm holds valid aspose license.

below is my sample code:
FileStream initialsImageStream = new FileStream(initialsPath, FileMode.Open);
FileStream signImageStream = new FileStream(signPath, FileMode.Open);

            DirectoryInfo directoryInfo = new DirectoryInfo(rootDirectory);
            FileInfo[] fileInfos = directoryInfo.GetFiles("*.pdf");

            string signedFilesDirectory = rootDirectory + "\\1";

            foreach (FileInfo file in fileInfos)
                Document pdfDocument = new Document(file.FullName);
                Page pdfPage = (Page)pdfDocument.Pages[1];

                TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("ABC");

                TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

                foreach (TextFragment txt in textFragmentCollection)
                    LLX = txt.Rectangle.LLX+20.0; //adding 20.0 to move to next cell. but each doc has different cell size
                    LLY = txt.Rectangle.LLY;
                    URX = txt.Rectangle.URX;
                    URY = txt.Rectangle.URY;
                    Console.WriteLine("{0}", txt.Rectangle);


                pdfPage.Contents.Add(new Aspose.Pdf.Operators.GSave());

                Rectangle rectangle = new Rectangle(LLX, LLY, URX, URY);
                //pdfPage.AddImage(initialsImageStream, rectangle);
                Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX + 25.0, rectangle.LLY });
                pdfPage.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix));
                XImage ximage = pdfPage.Resources.Images[pdfPage.Resources.Images.Count];
                pdfPage.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
                pdfPage.Contents.Add(new Aspose.Pdf.Operators.GRestore());

                Rectangle a_rectangle = new Rectangle(LLX + 100, LLY, URX, URY);//added 100 from actual text location but this is not working always as i cant predict how far second cell is from text.
                pdfPage.AddImage(signImageStream, a_rectangle);

                pdfDocument.Save(signedFilesDirectory + "\\" + file.Name);


We need to investigate the scenario in details and for the purpose, we may need a sample PDF document in which you are trying to add images. Please provide us with that document along with the information of cell against which you want to add images. We will test the scenario in our environment and address it accordingly.

Thanks for the response.
please find sample doc in the attachment.
“ABC” is my reference text. Need to place Images and date in the adjacent cells.
please note this table can be present anywhere in the doc and some docs will have only this table.
ABC text will be present in all types of doc though.

Please let me know if you need other details.excel.pdf (37.0 KB)


We tried to achieve the requirements using following code snippet with ImageStamp but could not get much success. Therefore, an investigation ticket has been logged in our issue tracking system as PDFNET-48493:

var textFragmentAbsorber = new TextFragmentAbsorber(@"{Image1}");
var textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;

Document pdfDocument = new Document(dataDir + "excel.pdf");

var textFragmentCollection = textFragmentAbsorber.TextFragments;//.Where(x => x.Text.Contains("Center")).ToList();

foreach (TextFragment textFragment in textFragmentCollection)
 ImageStamp stamp = new ImageStamp(dataDir + "aspose.jpg");
 stamp.Height = textFragment.Rectangle.Height;
 stamp.Width = textFragment.Rectangle.Width;
 stamp.XIndent = textFragment.Position.XIndent;
 stamp.YIndent = textFragment.Position.YIndent;
pdfDocument.Save(dataDir + "test20.6.out.pdf");

We will look into details of this scenario and investigate the feasibility of your requirements. We will inform you as soon as we have some certain updates regarding ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks for responding.
Can you please let me know if there is any ETA on this?
If not above mentioned approach, any other approach works.

Quick help is appreciated.


The ticket has recently been logged in our issue tracking system, so pending for analysis. It will be investigated and resolved on first come first serve basis. We are afraid that we cannot share any alternative approach or workaround before complete investigation of the logged-ticket. We will update you as soon as we have certain news on resolution of the ticket. Please spare us some time.

We are sorry for the inconvenience.