ByteScout PDF SDK - C# - Create Tables in PDF - ByteScout

ByteScout PDF SDK – C# – Create Tables in PDF

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Create Tables in PDF

How to create tables in PDF in C# using ByteScout PDF SDK

This code in C# shows how to create tables in PDF with this how to tutorial

These sample source codes on this page below are demonstrating how to create tables in PDF in C#. ByteScout PDF SDK can create tables in PDF. It can be used from C#. ByteScout PDF SDK is the library for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings.

C# code samples for C# developers help to speed up coding of your application when using ByteScout PDF SDK. Just copy and paste the code into your C# application’s code and follow the instruction. Further enhancement of the code will make it more vigorous.

Trial version of ByteScout PDF SDK can be downloaded for free from our website. It also includes source code samples for C# and other programming languages.

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

Program.cs
      
using System; using System.Diagnostics; using Bytescout.PDF; namespace Tables { /// <summary> /// This example demonstrates how to create tables. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); DeviceColor lightGrayColor = new ColorGray(200); DeviceColor whiteColor = new ColorGray(255); DeviceColor lightBlueColor = new ColorRGB(200, 200, 250); DeviceColor lightRedColor = new ColorRGB(255, 200, 200); // Create a table and set default background color Table table = new Table(); table.BackgroundColor = lightGrayColor; // Add row headers column and set its color table.Columns.Add(new TableColumn("RowHeaders")); table.Columns[0].BackgroundColor = lightGrayColor; // Add columns A, B, C, ... for (int c = 0; c < 10; c++) { string columnName = Convert.ToChar('A' + c).ToString(); table.Columns.Add(new TableColumn(columnName, columnName)); } // Add rows for (int r = 0; r < 10; r++) { // Create new row and set its background color TableRow row = table.NewRow(); row.BackgroundColor = whiteColor; // Set row header text row["RowHeaders"].Text = (r + 1).ToString(); // Set cell text for (int c = 0; c < 10; c++) { string columnName = Convert.ToChar('A' + c).ToString(); row[columnName].Text = columnName + (r + 1); } // Add the row to the table table.Rows.Add(row); } // Decorate the table table.Rows[1]["B"].BackgroundColor = lightRedColor; table.Columns[2].BackgroundColor = lightBlueColor; table.Rows[1].BackgroundColor = lightBlueColor; table.Rows[1]["RowHeaders"].BackgroundColor = lightBlueColor; // Draw the table on canvas page.Canvas.DrawTable(table, 20, 20); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } } }

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

VIDEO

ON-PREMISE VERSION INFORMATION

Get 60 Day Free Trial or Visit ByteScout PDF SDK Home Page

Explore ByteScout PDF SDK Documentation

Get ByteScout PDF SDK Free Training

WEB API

Get Your Free API Key

Explore Web API Documentation

Tutorials:

prev
next