How to insert images in a PdfLightTable?
You can insert images into a PdfLightTable by using the BeginCellLayout event handler at the specified row or cell index. Refer to the following code example to draw the image to row index 1:
C#
//Creates DataTable for the source. DataTable dataTable = new DataTable("myTable"); dataTable.Columns.Add("ID1"); dataTable.Columns.Add("ID2"); object[] values = new object[] { "Roll Number", "Student Name" }; dataTable.Rows.Add(values); values = new object[] { " ", " " }; dataTable.Rows.Add(values); values = new object[] { "011", "Clay" }; dataTable.Rows.Add(values); PdfLightTable table = new PdfLightTable(); // Subscribes the cell layout event. table.BeginCellLayout += new BeginCellLayoutEventHandler(table_BeginCellLayout); table.DataSource = dataTable; table.Style.CellPadding = 16; // Draws the table in a page. table.Draw(page.Graphics); doc.Save("Sample.pdf"); // Cell layout event handler. void table_BeginCellLayout(object sender, BeginCellLayoutEventArgs args) { if (args.RowIndex == 1) { PdfBitmap pBmp = new PdfBitmap(@"..\..\Data\logo.png"); args.Graphics.DrawImage(pBmp,args.Bounds); } }
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/PdfLightTableSample-1979834138.zip
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion:
I hope you enjoyed learning about how to insert images in a PdfLightTable.
You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!