Knowledgebase (2311)
Children categories
The PdfBorders class in Spire.PDF mainly contains three properties - DashStyle, Color and Width. By setting the value of these properties, you're able to change the appearance of grid border. In this article, I'll take color as an example to explain how to design gird border with Spire.PDF in C#.
As is shown in the following screenshot, Spire.PDF enables programmers to add color to PDF grid border as well as making the border as invisible.


Code Snippets:
Step 1: Create a new PDF document.
PdfDocument document = new PdfDocument(); PdfPageBase page=document.Pages.Add();
Step 2: Create a string array, create a 4 rows x 3 columns grid according to the length of string array. Set column width and row height.
String[] data
= {
"VendorName;Address;City",
"Cacor Corporation;161 Southfield Rd;Southfield",
"Underwater;50 N 3rd Street;Indianapolis",
"J.W. Luscher Mfg.;65 Addams Street;Berkely"
};
PdfGrid grid = new PdfGrid();
for (int r = 0; r < data.Length; r++)
{
PdfGridRow row = grid.Rows.Add();
}
grid.Columns.Add(3);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
grid.Columns[0].Width = width*0.15f;
grid.Columns[1].Width = width * 0.15f;
grid.Columns[2].Width = width * 0.15f;
float height=page.Canvas.ClientSize.Height-(grid.Rows.Count+1);
grid.Rows[0].Height = 12.5f;
grid.Rows[1].Height = 12.5f;
grid.Rows[2].Height = 12.5f;
grid.Rows[3].Height = 12.5f;
Step 3: Insert data into grid.
for (int r = 0; r < data.Length; r++)
{
String[] rowData = data[r].Split(';');
for (int c = 0; c < rowData.Length; c++)
{
grid.Rows[r].Cells[c].Value = rowData[c];
}
}
Step 4: Initialize a new instance of PdfBorders and set color property as LightBlue or Transparent. Apply border style to PDF grid.
PdfBorders border = new PdfBorders();
border.All = new PdfPen(Color.LightBlue);
foreach (PdfGridRow pgr in grid.Rows)
{
foreach (PdfGridCell pgc in pgr.Cells)
{
pgc.Style.Borders = border;
}
}
Step 5: Draw the grid on PDF and save the file.
PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));
document.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");
Entire Code:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Grid;
using System;
using System.Drawing;
namespace ChangeColorofGridBorder
{
class Program
{
static void Main(string[] args)
{
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
String[] data
= {
"VendorName;Address;City",
"Cacor Corporation;161 Southfield Rd;Southfield",
"Underwater;50 N 3rd Street;Indianapolis",
"J.W. Luscher Mfg.;65 Addams Street;Berkely"
};
PdfGrid grid = new PdfGrid();
for (int r = 0; r < data.Length; r++)
{
PdfGridRow row = grid.Rows.Add();
}
grid.Columns.Add(3);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
grid.Columns[0].Width = width * 0.15f;
grid.Columns[1].Width = width * 0.15f;
grid.Columns[2].Width = width * 0.15f;
float height = page.Canvas.ClientSize.Height - (grid.Rows.Count + 1);
grid.Rows[0].Height = 12.5f;
grid.Rows[1].Height = 12.5f;
grid.Rows[2].Height = 12.5f;
grid.Rows[3].Height = 12.5f;
//insert data to grid
for (int r = 0; r < data.Length; r++)
{
String[] rowData = data[r].Split(';');
for (int c = 0; c < rowData.Length; c++)
{
grid.Rows[r].Cells[c].Value = rowData[c];
}
}
grid.Rows[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
//Set borders color to LightBule
PdfBorders border = new PdfBorders();
border.All = new PdfPen(Color.LightBlue);
foreach (PdfGridRow pgr in grid.Rows)
{
foreach (PdfGridCell pgc in pgr.Cells)
{
pgc.Style.Borders = border;
}
}
PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));
document.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");
}
}
}
Spire.Presentation is a powerful and standalone .NET component which designed for developers to operate the PowerPoint documents in C# and VB.NET. Spire.Presentation enable developers to insert a new table, remove rows or columns in an existing table, and remove the whole table from the presentation slides. This article we will show you how to add a row to an existing table in presentation slide by using C# code.
Step 1: Create Presentation instance and load file.
Presentation ppt = new Presentation();
ppt.LoadFromFile("table.pptx");
Step 2: Get the table within the PowerPoint document.
ITable table = ppt.Slides[0].Shapes[4] as ITable;
Step 3: Add a new row into the PowerPoint table and set the data for the cells in the new row.
//Get the first row TableRow row = table.TableRows[0]; //Clone the row and add it to the end of table table.TableRows.Append(row); int rowCount = table.TableRows.Count; //Get the last row TableRow lastRow = table.TableRows[rowCount - 1]; //Set new data of the first cell of last row lastRow[0].TextFrame.Text = " The first cell"; //Set new data of the second cell of last row lastRow[1].TextFrame.Text = " The second cell";
Step 4: Save the document and preview it.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
Effective screenshot:

Full codes:
using Spire.Presentation;
namespace AddRow
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("table.pptx");
ITable table = ppt.Slides[0].Shapes[4] as ITable;
TableRow row = table.TableRows[0];
table.TableRows.Append(row);
int rowCount = table.TableRows.Count;
TableRow lastRow = table.TableRows[rowCount - 1];
lastRow[0].TextFrame.Text = "The first cell";
lastRow[1].TextFrame.Text = "The second cell";
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");
}
}
}
Spire.Presentation offer developers an easy way to add the watermarks to the presentation slides. There are two kinds of watermarks in PowerPoint documents: text watermark and image watermark. We'll learn how to add image watermark in PowerPoint document via Spire.Presentation.
The goal of the article is to make an image as a background img watermark as following screenshot.

Here comes to the steps of how to add image watermarks in C#:
Step 1: Create a presentation document and load the document from the file
Presentation ppt = new Presentation(); ppt.LoadFromFile(fileName);
Step 2: Get the image you want to add as image watermark.
IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));
Step 3: Set the properties of SlideBackground, and then fill the image as watermark.
ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom; ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture; ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType=PictureFillType.Stretch; ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
step4: Save the document to a new file.
ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);
Full codes:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddimageWatermark
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile(fileName);
IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));
ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
if (fileExtensions == ".ppt")
{
ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);
}
else
{
ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.Pptx2007);
}
Viewer(resultFileName);
}
}
}