Add Table to PDF (.NET Core/Framework)

Adding a table to a PDF using DynamicPDF Core Suite is straightforward, as the example on this page illustrates.

Watch the Video

How to Add a Table to a PDF in C#

The following steps and sample code illustrates adding a table to a PDF document using DynamicPDF Core Suite.

Steps for Adding a Table to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document instance.
  3. Create a Table2 object.
  4. Create Column2 object and columns to the table.
  5. Create Row2 object and add rows to the table.
  6. Create Cell2 object to add the cells to rows.
  7. Set the necessary table parameters (Border, Cell spacing, Cell padding).
  8. Add the table to the Page instance.
  9. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
Table2 table = new Table2(0, 0, 600, 600);
Column2 column1 = table.Columns.Add(150);
column1.CellDefault.Align = TextAlign.Center;
Row2 row1 = table.Rows.Add(40, Font.HelveticaBold, 16, Grayscale.Black, Grayscale.Gray);
row1.CellDefault.Align = TextAlign.Center;
row1.CellDefault.VAlign = VAlign.Center;
row1.Cells.Add("Header 1");
row1.Cells.Add("Header 2");
row1.Cells.Add("Header 3");
row1.Cells.Add("Header 4");
Row2 row2 = table.Rows.Add(30);
Cell2 cell1 = row2.Cells.Add("Rowheader 1", Font.HelveticaBold, 16, Grayscale.Black, Grayscale.Gray, 1);
cell1.Align = TextAlign.Center;
cell1.VAlign = VAlign.Center;
row2.Cells.Add("Item 1");
row2.Cells.Add("Item 2");
row2.Cells.Add("Item 3");
Row2 row3 = table.Rows.Add(30);
Cell2 cell2 = row3.Cells.Add("Rowheader 2", Font.HelveticaBold, 16, Grayscale.Black, Grayscale.Gray, 1);
cell2.Align = TextAlign.Center;
cell2.VAlign = VAlign.Center;
row3.Cells.Add("Item 4");
row3.Cells.Add("Item 5");
row3.Cells.Add("Item 6");
table.CellDefault.Padding.Value = 5.0f;
table.CellSpacing = 5.0f;
table.Border.Top.Color = RgbColor.Blue;
table.Border.Bottom.Color = RgbColor.Blue;
table.Border.Top.Width = 2;
table.Border.Bottom.Width = 2;
table.Border.Left.LineStyle = LineStyle.None;
table.Border.Right.LineStyle = LineStyle.None;

GitHub Project

Clone or view the example project at GitHub. This example code is contained in the Examples/TableExample.cs file.

Clone or View Example Project on GitHub

Getting Started

NuGet Package

DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download the package directly from NuGet.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information

Adding a table to a PDF is just one of DynamicPDF Core Suite's over 75 page elements you can use to add rich content to the PDFs you create. Using these elements, you can create:

  • Images,
  • Text Objects (TextArea and Label),
  • HTML,
  • Barcodes (47 types),
  • Form Fields,
  • and Charts.

More information on DynamicPDF Core Suite can be found on its website.

  • [DynamicPDF Core Suite for .NET](https://www.dynamicpdf.com/docs/dotnet/dynamic-pdf-core-suite-welcome"Create PDFs in .NET Core")

Available on Other Platforms

DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!