Hi,
Hi there,
Thanks. It works for me.
Hi Iris,
Thanks for your feedback. To fit an image into a cell you need to set Image height/width accordingly. Please check the following sample code snippet. Hopefully, it will help you to accomplish your requirements.
Pdf pdf1 = new Pdf();
//Create the section in the Pdf object
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Generator.Table headerTable = new Aspose.Pdf.Generator.Table();
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(headerTable);
headerTable.ColumnWidths = "100%";
var row1 = headerTable.Rows.Add();
row1.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
row1.DefaultCellTextInfo.FontName = "Helvetica-Bold";
row1.DefaultCellTextInfo.FontSize = 16;
var cell1 = row1.Cells.Add("Title");
cell1.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;
var row2 = headerTable.Rows.Add();
row2.FixedRowHeight = 600;
Aspose.Pdf.Generator.Cell cell2 = row2.Cells.Add("");
cell2.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;
Aspose.Pdf.Generator.Image logo = new Aspose.Pdf.Generator.Image();
logo.ImageInfo.File = myDir + "sunset.jpg";
logo.ImageInfo.ImageFileType = ImageFileType.Jpeg;
logo.ImageInfo.FixHeight = row2.FixedRowHeight;
logo.ImageInfo.FixWidth = sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left - sec1.PageInfo.Margin.Right;
Text imageContainer = new Text();
Segment imageSegment = new Segment();
imageSegment.InlineParagraph = logo;
imageContainer.Segments.Add(imageSegment);
cell2.Paragraphs.Add(imageContainer);
pdf1.Save(myDir + "Table_ImageGen.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
Thanks for your reply.
Hi Iris,
Hi Iris,
Thanks for your patience. Please use the following code snippet to find the remaining space on the page to fit an image to the same page. Hopefully, it will serve the purpose.
.....
.....
// to find remaining space in page for image height deduct page top margin, page bottom margin,
// table height, table top margin, pagerBorderMaring top and bottom from page height
logo.ImageInfo.FixHeight =
sec1.PageInfo.PageHeight - sec1.PageInfo.Margin.Top -
sec1.PageInfo.Margin.Bottom -
headerTable.GetHeight(pdf1) - headerTable.Margin.Top -
sec1.PageInfo.PageBorderMargin.Top - sec1.PageInfo.PageBorderMargin.Bottom;
logo.ImageInfo.FixWidth =
sec1.PageInfo.PageWidth - sec1.PageInfo.Margin.Left -
sec1.PageInfo.Margin.Right;
...
Please feel free to contact us for any further assistance.
Best Regards,