I'm trying to create a PdfTable where one column is an image. I do not have a database connection like in the samples. My code looks like that:
- Code: Select all
PdfTable table = new PdfTable();
table.Style.BorderPen = new PdfPen(brush1, 0.75f);
table.Style.ShowHeader = true;
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("Icon", typeof(PdfImage)));
dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
foreach (var legendItem in legendItems)
{
DataRow row = dataTable.NewRow();
PdfImage pdfImage = PdfImage.FromImage(legendItem.Value);
row["Icon"] = pdfImage;
row["Name"] = legendItem.Key;
dataTable.Rows.Add(row);
}
table.DataSourceType = PdfTableDataSourceType.TableDirect;
table.DataSource = dataTable;
float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
table.Columns[0].Width = width * 0.24f * width;
table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
table.Columns[1].Width = width * 0.21f * width;
table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
Doing so the table looks like that:
Icon Name
Spire.Pdf.Graphics.PdfBitmap String 1
Spire.Pdf.Graphics.PdfBitmap String 2
Spire.Pdf.Graphics.PdfBitmap String 3
How do I set the image in the DataTable so it is rendered correctly?
Best Regards,
Torsten