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

Free Support Forum - aspose.com

Not able to add image to table cell using c# code

Hi Aspose team,

I already raised ticket regarding not able to add checkbox to table cell. Again now i am not able to add image to table cell. below is my piece of code i am trying to add.

Aspose.Pdf.Image ticktMark = new Aspose.Pdf.Image();
ticktMark.File = HostingEnvironment.MapPath(@"~/Content/Images/tickmark.png");
ticktMark.FixHeight = 30;
ticktMark.FixWidth = 40;
Cell chkbxCell = new Cell();
chkbxCell.VerticalAlignment = VerticalAlignment.Center;
chkbxCell.Paragraphs.Add(ticktMark);
tableobj.Rows[i].Cells.Add(chkbxCell);

NOTE: Also i am not getting intellisence for some properties like characteristics, sections, segment. i am using aspose pdf version 18.3.0.0. Pleas help me with complete code creating table and adding image to table cell to avoid release extension. Thanks!!

@shareefyahya

Thank you for creating separate topic for separate problem.

We would like to request you to use below code snippet in your environment and then share your kind feedback with us. It adds an image to a table cell as per your requirements.

        // Instantiate Document object
        Document doc = new Document();
        // Create an image instance
        Aspose.Pdf.Image img = new Aspose.Pdf.Image();
        // Path for source file
        img.File = dataDir + "tick.png";
        // Set width for image instance
        img.FixWidth = 50;
        // Set height for image instance
        img.FixHeight = 50;
        // Create table instance
        Aspose.Pdf.Table table = new Aspose.Pdf.Table();
        // Set width for table cells
        table.ColumnWidths = "60 60";
        table.DefaultCellBorder = new BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
        // Create row object and add it to table instance
        Aspose.Pdf.Row row = table.Rows.Add();
        // Create cell object and add it to row instance
        Aspose.Pdf.Cell cell = row.Cells.Add();
        // Add textfragment to paragraphs collection of cell object
        cell.Paragraphs.Add(new TextFragment("First cell"));
        // Add another cell to row object
        cell = row.Cells.Add();
        // Add SVG image to paragraphs collection of recently added cell instance
        cell.Paragraphs.Add(img);
        // Create page object and add it to pages collection of document instance
        Aspose.Pdf.Page page = doc.Pages.Add();
        // Add table to paragraphs collection of page object
        page.Paragraphs.Add(table);

        dataDir = dataDir + "ImageCell.pdf";
        // Save PDF file
        doc.Save(dataDir);

Regarding intellisence, please create a separate topic while sharing a narrowed down sample application along with all details so that we may investigate and assist you accordingly.