Articles in this section
Category / Section

How to group contents in a PdfLightTable?

2 mins read

Currently WinForms PDF do not have the support to group the contents present in the table. To achieve this, group the input DataTable before applying the values to PdfLightTable.

Assemblies Required:

  1. Syncfusion.Pdf.Base.dll
  2. Syncfusion.Compression.Base.dll

The below code snippet illustrates how to group the contents in a PdfLightTable.

C#

 
//Create new PDF document instance
PdfDocument document = new PdfDocument();
            
#region Style for Table
            
// Creating Border with transparent color.
 PdfPen borderPen = new PdfPen(Color.Black);
 borderPen.Width = 1.0f;
 
// Assigning the border pen to table cell.
PdfCellStyle defStyle = new PdfCellStyle();
defStyle.BorderPen = borderPen;
 
PdfLightTableLayoutFormat format = new PdfLightTableLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
#endregion
 
#region Functionality for the requirement
//Sorting the Data table
dataTable.DefaultView.Sort = "Column1 asc";
dataTable = dataTable.DefaultView.ToTable();
 
string lastValue = dataTable.Rows[0][0] as string;
DataTable tempDataTable = new DataTable();
tempDataTable = dataTable.Clone();
            
//logic to seperate the Data table
foreach (DataRow row in dataTable.Rows)
   {
      if (lastValue == row.ItemArray[0] as string)
       {
         tempDataTable.Rows.Add(row.ItemArray);
       }
      else
       {
         lastValue = row.ItemArray[0] as string;
         //Creating the PdfLightTAble
         PdfLightTable tblPDF = new PdfLightTable();
         tblPDF.Style.DefaultStyle = defStyle;
         tblPDF.Style.ShowHeader = true;
         tblPDF.Style.RepeatHeader = false;
                   
         //Assigning the Data source
          tblPDF.DataSource = tempDataTable;
                   
         //Drawing the table
         tblPDF.Draw(document.Pages.Add(), 0, 0);
         tempDataTable = new DataTable();
         tempDataTable = dataTable.Clone();
            }
      }
     tempDataTable.Rows.Add(dataTable.Rows[dataTable.Rows.Count - 1].ItemArray);
     PdfLightTable tblPDF1 = new PdfLightTable();
     tblPDF1.Style.DefaultStyle = defStyle;
     tblPDF1.Style.ShowHeader = true;
     tblPDF1.Style.RepeatHeader = false;
     tblPDF1.DataSource = tempDataTable;
 
     tblPDF1.Draw(document.Pages.Add(), 0, 0);
#endregion
 
//Saving the PDF document
document.Save("Sample1.pdf");
document.Close(true);
System.Diagnostics.Process.Start("Sample1.pdf");
this.Close();

 

The working sample can be downloaded from the below link:

https://www.syncfusion.com/downloads/support/directtrac/general/PDFlight_table-205499629.zip

Conclusion

I hope you enjoyed learning about how to group contents in a Pdf Light Table.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations.

For current customers, you can check out our WinForms  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 sign in to leave a comment
Access denied
Access denied