//Create a new PDF document
PdfDocument pdfDocument = new PdfDocument();
//Add page to the PDF document
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create a new PdfGrid
PdfGrid pdfGrid = new PdfGrid();
//Add three columns
pdfGrid.Columns.Add(3);
//Add header
pdfGrid.Headers.Add(1);
PdfGridRow pdfGridHeader = pdfGrid.Headers[0];
pdfGridHeader.Cells[0].Value = "Employee ID";
pdfGridHeader.Cells[1].Value = "Employee Name";
pdfGridHeader.Cells[2].Value = "Salary";
//Add rows
PdfGridRow pdfGridRow = pdfGrid.Rows.Add();
pdfGridRow.Cells[0].Value = "E01";
pdfGridRow.Cells[1].Value = "Clay";
pdfGridRow.Cells[2].Value = "$10,000";
//Load the image from the stream
FileStream fs = new FileStream(@"Image file path", FileMode.Open);
//Apply style
PdfGridCell pdfGridCell = pdfGrid.Rows[0].Cells[0];
//Set the cell value as the bitmap image
pdfGridCell.Value = new PdfBitmap(fs);
pdfGrid.Rows[0].Height = 50;
//Draw the PdfGrid
pdfGrid.Draw(pdfPage, PointF.Empty);
MemoryStream ms = new MemoryStream();
//Save the document
pdfDocument.Save(ms);
//Close the document
pdfDocument.Close(true); |