)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to draw more than one table sequentially in PDF using C#, VB.NET

Platform: WinForms |
Control: PDF |
Published Date: January 20, 2016 |
Last Revised Date: May 6, 2019

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can draw more than one table sequentially in a PDF.

Steps to draw more than one table sequentially in the PDF programmatically:

  1. Create a new C# console application project. Create new console application
  2. Install the Syncfusion.Pdf.WinForms NuGet packages as reference to your .NET Framework application from NuGet.org. Install nuget packages
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using Syncfusion.Pdf.Tables;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Grid
Imports Syncfusion.Pdf.Tables

 

  1. Use the following code snippet to draw the table one after another in the PDF.

C#

//Create a new PDF document
PdfDocument document = new PdfDocument();
 
//Add a new PDF page
PdfPage page = document.Pages.Add();
 
//Create font with bold style
PdfFont boldFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
 
//Create font with regular style
PdfFont regularFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Regular);
 
//Draw the string with bold style font
page.Graphics.DrawString("PdfGrid", boldFont, PdfBrushes.Black, PointF.Empty);
 
//Create PdfGrid
PdfGrid pdfGrid = new PdfGrid();
 
//Create a DataTable
DataTable dataTable = new DataTable();
 
//Add columns to the DataTable
dataTable.Columns.Add("ID");
 
dataTable.Columns.Add("Name");
 
dataTable.Columns.Add("Age");
 
dataTable.Columns.Add("Salary");
 
//Add rows to the DataTable dataTable.Rows.Add(new object[] { "E01", "Clay","25","20000" });
 
dataTable.Rows.Add(new object[] { "E02", "Thomas","30","35000" });
 
//Assign data source
pdfGrid.DataSource = dataTable;
 
//Assign bold font to pdfGrid header
pdfGrid.Headers[0].Style.Font = boldFont;
 
//Assign font to PdfGrid
pdfGrid.Style.Font = regularFont;
 
//Draw grid to the PDF document page
PdfGridLayoutResult result = pdfGrid.Draw(page, new PointF(0, 20));
 
page.Graphics.DrawString("PdfLightTable", boldFont, PdfBrushes.Black, new PointF(0, result.Bounds.Bottom + 10));
 
//Declare a PdfLightTable
PdfLightTable pdfLightTable = new PdfLightTable();
 
//Set the data source as direct
pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect;
 
//Create columns
pdfLightTable.Columns.Add(new PdfColumn("ID"));
 
pdfLightTable.Columns.Add(new PdfColumn("Name"));
 
pdfLightTable.Columns.Add(new PdfColumn("Age"));
 
pdfLightTable.Columns.Add(new PdfColumn("Salary"));
 
//Add rows
pdfLightTable.Rows.Add(new object[] { "#E01", "@Clay", "25", "20000" });
 
pdfLightTable.Rows.Add(new object[] { "#E02", "@Thomas","30", "35000" });
 
pdfLightTable.Style.ShowHeader = true;
 
pdfLightTable.Style.HeaderStyle = new PdfCellStyle();
pdfLightTable.Style.HeaderStyle.Font = boldFont;
 
pdfLightTable.Style.DefaultStyle = new PdfCellStyle();
pdfLightTable.Style.DefaultStyle.Font = regularFont;
 
//Draw the PdfLightTable
pdfLightTable.Draw(result.Page, new PointF(0, result.Bounds.Bottom + 30));
 
//Save the PDF document
document.Save("Tables.pdf");
 
//Close the PDF document
document.Close(true);
 
//This will open the PDF file so, the result will be seen in default PDF Viewer
 
System.Diagnostics.Process.Start("Tables.pdf");

 

VB.NET

'Create a new PDF document
Dim document As New PdfDocument()
 
'Add a new PDF page
Dim page As PdfPage = document.Pages.Add()
 
'Create font with bold style
Dim boldFont As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12.0F, PdfFontStyle.Bold)
 
'Create font with regular style
Dim regularFont As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12.0F, PdfFontStyle.Regular)
 
'Draw the string with bold style font
page.Graphics.DrawString("PdfGrid", boldFont, PdfBrushes.Black, PointF.Empty)
 
'Create PdfGrid
Dim pdfGrid As New PdfGrid()
 
'Create a DataTable
Dim dataTable As New DataTable()
 
'Add columns to the DataTable
dataTable.Columns.Add("ID")
 
dataTable.Columns.Add("Name")
 
dataTable.Columns.Add("Age")
 
dataTable.Columns.Add("Salary")
 
'Add rows to the DataTable
dataTable.Rows.Add(New Object() {"E01", "Clay", "25", "20000"})
 
dataTable.Rows.Add(New Object() {"E02", "Thomas", "30", "35000"})
 
'Assign data source
pdfGrid.DataSource = dataTable
 
'Assign bold font to pdfGrid header
pdfGrid.Headers(0).Style.Font = boldFont
 
'Assign font to PdfGrid
pdfGrid.Style.Font = regularFont
 
'Draw grid to the PDF document page
Dim result As PdfGridLayoutResult = pdfGrid.Draw(page, New PointF(0, 20))
 
page.Graphics.DrawString("PdfLightTable", boldFont, PdfBrushes.Black, New PointF(0, result.Bounds.Bottom + 10))
 
'Declare a PdfLightTable
Dim pdfLightTable As New PdfLightTable()
 
'Set the data source as direct
pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect
 
'Create columns
pdfLightTable.Columns.Add(New PdfColumn("ID"))
 
pdfLightTable.Columns.Add(New PdfColumn("Name"))
 
pdfLightTable.Columns.Add(New PdfColumn("Age"))
 
pdfLightTable.Columns.Add(New PdfColumn("Salary"))
 
'Add rows
pdfLightTable.Rows.Add(New Object() {"#E01", "@Clay", "25", "20000"})
 
pdfLightTable.Rows.Add(New Object() {"#E02", "@Thomas", "30", "35000"})
 
pdfLightTable.Style.ShowHeader = True
 
pdfLightTable.Style.HeaderStyle = New PdfCellStyle()
pdfLightTable.Style.HeaderStyle.Font = boldFont
 
pdfLightTable.Style.DefaultStyle = New PdfCellStyle()
pdfLightTable.Style.DefaultStyle.Font = regularFont
 
'Draw the PdfLightTable
pdfLightTable.Draw(result.Page, New PointF(0, result.Bounds.Bottom + 30))
 
'Save the PDF document
document.Save("Tables.pdf")
 
'Close the document
document.Close(True)
 
'This will open the PDF file so, the result will be seen in default PDF Viewer
System.Diagnostics.Process.Start("Tables.pdf")

 

  1. You can download the working sample from TableSample.Zip.
  2. By executing the program, the tables will be drawn one after another. You can get the PdfGrid and PdfLightTable rendered bounds in PdfGridLayoutResult and PdfLightTableLayoutResult class respectively. You will get the PDF document as follows. Screenshot of output PDF document

Take a moment to peruse the documentation, where you will find other options like create simple table, cell customization, and table styles.

Refer here to explore the rich set of Syncfusion Essential PDF features.

An online sample link demonstrates how to draw table one after another in the PDF. 

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon