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

Free Support Forum - aspose.com

Adding an image into a table


Is there any way to insert an XImage from the resources (or any kind of image) into a Cell from a Table?

var table = new Table();
var row = table.Rows.Add();
var cell = row.Cells.Add();
//add image to cell?

Thank you.


Thank you for contacting support.

Please try below code snippet to add an image in a table cell, and then share your kind feedback with us.

// 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 + "aspose-logo.jpg";
// Set width for image instance
img.FixWidth = 60;
// Set height for image instance
img.FixHeight = 60;
// 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 image to paragraphs collection of recently added cell instance
// 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
dataDir = dataDir + "ImageCell_18.11.pdf";
// Save PDF file

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thank you for the snippet!