Add Image to Table

I am attempting to add an image to a table using the Aspose.Pdf namespaces and the process hangs on the call to Save(). I have seen how to do it using the Generator namespaces, but I would rather use the newer DOM based apis.


Here is the code:

var document = new Document();
var page = document.Pages.Add();
page.BleedBox = new Rectangle(9f, 711f + 9f, 468f + 9f, 0f);
page.TrimBox = new Rectangle(9f, 720f, 468f + 9f, 9f);
page.PageInfo.Height = 711f + 9f + 9f;
page.PageInfo.Width = 468f + 9f;

var table = new Table();
table.Left = 100;
table.Top = 100;
table.ColumnWidths = “100 100 100”;
table.Border = new BorderInfo(BorderSide.All, 1f, Color.DarkBlue);
for (var i = 0; i < 3; i++) {
var row = table.Rows.Add();
for (var j = 0; j < 3; j++) {
var cell = row.Cells.Add();
cell.BackgroundColor = Color.Yellow;
}
}
var image = new Image { File = @“C:\Users\Jonathan\Downloads\logos\3M.png”, FixWidth = 100 };
table.Rows[1].Cells[1].Paragraphs.Add(image);
page.Paragraphs.Add(table);
document.Save(@“C:\Users\Jonathan\Downloads\logos\learnAspose.pdf”);

I just recently purchased Aspose.Pdf and I am trying to wrap my mind around it.

Thanks,

Jon

Hi Jon,


Thanks for your inquiry. I’m afraid I’m unable to notice any issue, while testing your code with Aspose.Pdf for .NET 7.9.0. Please find enclosed sample output. Can you please download and try latest version? Hopefully your issue will be resolved.

var document = new Document();
var page = document.Pages.Add();
page.BleedBox = new Aspose.Pdf.Rectangle(9f, 711f + 9f, 468f + 9f, 0f);
page.TrimBox = new Aspose.Pdf.Rectangle(9f, 720f, 468f + 9f, 9f);
page.PageInfo.Height = 711f + 9f + 9f;
page.PageInfo.Width = 468f + 9f;

var table = new Aspose.Pdf.Table();
table.Left = 100;
table.Top = 100;
table.ColumnWidths = “100 100 100”;
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1f, System.Drawing.Color.DarkBlue);
for (var i = 0; i < 3; i++)
{
var row = table.Rows.Add();
for (var j = 0; j < 3; j++)
{
var cell = row.Cells.Add();
cell.BackgroundColor = System.Drawing.Color.Yellow;
}
}
var image = new Aspose.Pdf.Image { File = myDir + “aspose.pdf-JR_logo.png”, FixWidth = 100 };

table.Rows[1].Cells[1].Paragraphs.Add(image);
page.Paragraphs.Add(table);
document.Save(myDir+“learnAspose.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,