Articles in this section
Category / Section

How to set style for single cell in PdfLightTable?

4 mins read

Set style for single cell in PdfLightTable

Style can be applied to a single cell in PdfLightTable by using BeginCellLayout event handler.

Please refer to the following code example how to set the style for single cell in PdfLightTable:

// Create the PDF document
PdfDocument doc = new PdfDocument();
// Add the page
PdfPage page = doc.Pages.Add();
// Create the light table
PdfLightTable pdfLightTable = new PdfLightTable();
// Set Data source
pdfLightTable.DataSource = GetData();
// Call the event handlers
pdfLightTable.BeginCellLayout += pdfLightTable_BeginCellLayout;
// Draw the table
pdfLightTable.Draw(page, new RectangleF(new PointF(margin, 70), new SizeF(100, 100)));
// Save and close the document
doc.Save("sample.pdf");
doc.Close(true);

// Begin cell layout
private void pdfLightTable_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
{
    if (args.RowIndex == 0 && args.CellIndex == 0)
    {
        // Skip the cell
        args.Skip = true;
        // Draw the cell
        args.Graphics.DrawRectangle(PdfPens.Black, args.Bounds);
        // Draw the background brush
        args.Graphics.DrawRectangle(PdfBrushes.LightBlue, args.Bounds);
        // Draw the string in the cell
        args.Graphics.DrawString("Cell Style", new PdfStandardFont(PdfFontFamily.Courier, 10), PdfBrushes.Black, new PointF(args.Bounds.X, args.Bounds.Y));
    }
}

 

Sample link:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample1585146640

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from 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 set style for single cell in PdfLightTable.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied