Articles in this section
Category / Section

How to paginate a table in PDF page using C# and VB.NET?

3 mins read

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can paginate a table in the PDF page using C# and VB.NET.

Steps to paginate a table in PDF page programmatically:

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

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using System.Drawing;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Grid
Imports System.Drawing

 

  1. Use the following code snippet to paginate a table in PDF page.

C#

//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a page
PdfPage page = document.Pages.Add();
//Create a PdfGrid
PdfGrid pdfGrid = new PdfGrid();
//Create a data table
DataTable dataTable = new DataTable();
//Add columns to the DataTable
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("Name", typeof(string));
dataTable.Columns.Add("Type", typeof(string));
dataTable.Columns.Add("Date", typeof(DateTime));
//Add rows to the DataTable
for (int i = 0; i < 20; i++)
{
    dataTable.Rows.Add(57, "AAA", "ABC", DateTime.Now);
    dataTable.Rows.Add(130, "BBB", "BCD", DateTime.Now);
    dataTable.Rows.Add(92, "CCC", "CDE", DateTime.Now);
}
//Assign data source
pdfGrid.DataSource = dataTable;
//Set properties to paginate the grid
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
layoutFormat.Break = PdfLayoutBreakType.FitPage;
layoutFormat.Layout = PdfLayoutType.Paginate;
//Draw grid to the page of PDF document
pdfGrid.Draw(page, new PointF(10, 10), layoutFormat);
// Save the document
document.Save("Table.pdf");
//Close the document
document.Close(true);
//This will open the PDF file so, the result will be seen in default PDF Viewer 
Process.Start("Table.pdf");

 

VB.NET

'Create a new PDF document
Dim document As New PdfDocument()
'Add a page
Dim page As PdfPage = document.Pages.Add()
'Create a PdfGrid
Dim pdfGrid As New PdfGrid()
'Create a data table
Dim dataTable As New DataTable()
'Add columns to the DataTable
dataTable.Columns.Add("ID", GetType(Integer))
dataTable.Columns.Add("Name", GetType(String))
dataTable.Columns.Add("Type", GetType(String))
dataTable.Columns.Add("Date", GetType(DateTime))
'Add rows to the DataTable
For i As Integer = 0 To 19
    dataTable.Rows.Add(57, "AAA", "ABC", DateTime.Now)
    dataTable.Rows.Add(130, "BBB", "BCD", DateTime.Now)
    dataTable.Rows.Add(92, "CCC", "CDE", DateTime.Now)
Next
'Assign data source
pdfGrid.DataSource = dataTable
'Set properties to paginate the grid
Dim layoutFormat As New PdfGridLayoutFormat()
layoutFormat.Break = PdfLayoutBreakType.FitPage
layoutFormat.Layout = PdfLayoutType.Paginate
'Draw grid to the page of PDF document
pdfGrid.Draw(page, New PointF(10, 10), layoutFormat)
' Save the document
document.Save("Table.pdf")
'Close the document
document.Close(True)
'This will open the PDF file so, the result will be seen in default PDF Viewer 
Process.Start("Table.pdf")

 

A complete working sample can be downloaded from TablePaginateSample.zip.

Take a moment to peruse the documentation, where you can find other options like creating a table using PdfLightTable and PdfGrid, cell and row customization in PdfLightTable and PdfGrid, built-in table styles to PdfGrid with code examples.

An online sample link for creation of simple table report with pagination in the PDF document.

Refer here to learn more about PDF Tables.

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.

 

Conclusion

I hope you enjoyed learning about need to paginate a table in PDF page using C# and VB.NET.

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 Diagram 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 forumsDirect-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