Manage Tables in PDF using C#

Add, Extract, Delete Tables in PDF document. Use Aspose.PDF for .NET to modify PDF files programmatically

Most popular action with Tables via C#

How to manage Tables in PDF document using Aspose.PDF for .NET library

In order to work with table, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Add Table to PDF using C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Access the Page via its index.
  3. Create Table object.
  4. Set table settings (e.g. set the borders).
  5. Populate table.
  6. Add the table to a page.
  7. Save the file.

Add Table in PDF - C#

var inputFile = Path.Combine(dataDir, "sample.pdf");
var outputFile = Path.Combine(dataDir, "sample_with_table_out.pdf");

var pdfDocument = new Aspose.Pdf.Document(inputFile);
var table = new Aspose.Pdf.Table
{
    Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.LightGray),
    DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.LightGray)
};
for (int row_count = 1; row_count < 10; row_count++)
{
    Aspose.Pdf.Row row = table.Rows.Add();
    row.Cells.Add("Column (" + row_count + ", 1)");
    row.Cells.Add("Column (" + row_count + ", 2)");
    row.Cells.Add("Column (" + row_count + ", 3)");
}

pdfDocument.Pages[1].Paragraphs.Add(table);
pdfDocument.Save(outputFile);