//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a page
PdfPage page = document.Pages.Add();
//Create a PdfLightTable
PdfLightTable pdfLightTable = new PdfLightTable();
//Create a data table
DataTable dataTable = new DataTable();
//Add columns to data table
dataTable.Columns.Add("Text");
dataTable.Columns.Add("Image");
//Add rows to data table
dataTable.Rows.Add("Adventure Cycle", "");
//Assign data source
pdfLightTable.DataSource = dataTable;
pdfLightTable.BeginCellLayout += pdfLightTable_BeginCellLayout;
pdfLightTable.BeginRowLayout += PdfLightTable_BeginRowLayout;
pdfLightTable.Style.ShowHeader = true;
//Draw light table to the page of PDF document
pdfLightTable.Draw(page, new RectangleF(0, 50, page.GetClientSize().Width, page.GetClientSize().Height)); |
private void PdfLightTable_BeginRowLayout(object sender, BeginRowLayoutEventArgs args)
{
if (args.RowIndex == 0)
args.MinimalHeight = 100;
}
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
//Draw image in the same cell
if (args.RowIndex==0 && args.CellIndex == 1)
{
//Load the image as stream
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Image.jpg");
PdfBitmap image = new PdfBitmap(imageStream);
//Draw image
args.Graphics.DrawImage(image, args.Bounds.X, args.Bounds.Y , args.Bounds.Width, args.Bounds.Height);
}
} |