Skip to main content

Table

Version: 12.0

Adding Tables to PDFs

Adding a table to a PDF using DynamicPDF Core Suite for .NET is straightforward, as the following C# example illustrates.

Watch the Video​

YouTube thumbnail: Watch video: How to add a Table to a PDF in .NETWatch video: How to add a Table to a PDF in .NET

How to Add Table to PDF​

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

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. Add the Document object's Draw method to draw and save the PDF document.

Sample Code - C#​

Document document = new Document();
Page page = new Page();
document.Pages.Add(page);

Table2 table = new Table2(0, 0, 600, 600);

Column2 column1 = table.Columns.Add(150);
column1.CellDefault.Align = TextAlign.Center;
table.Columns.Add(90);
table.Columns.Add(90);
table.Columns.Add(90);

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;

page.Elements.Add(table);
document.Draw(@"Output.pdf");

GitHub Project​

An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub

View source on GitHub: Core Suite .NET Core Examples

Getting Started​

Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing.

NuGet Package​

The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.

Get ceTe.DynamicPDF.CoreSuite.NET from NuGet

DynamicPDF Core Suite Information​

DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!

More Information on Tables​

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.