.NET (1322)
Children categories
How to use uninstalled font when converting Doc to PDF via Spire.Doc
2015-03-25 03:21:26 Written by KoohjiNow Spire.Doc support using uninstalled font when converting Doc to PDF to diversity text content. In this article, we'll talk about how to realize this function:
Step 1: Download a font uninstalled in system.

Step 2: Create a new blank Word document.
Document document = new Document();
Step 3: Add a section and create a new paragraph.
Section section = document.AddSection(); Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();
Step 4: Append text for a txtRange.
TextRange txtRange = paragraph.AppendText(text);
Step 5: Create an example for class ToPdfParameterList named to pdf, and create a new PrivateFontPathlist for property PrivateFontPaths, instantiate one PrivateFontPath with name and path of downloaded font.
ToPdfParameterList toPdf = new ToPdfParameterList()
{
PrivateFontPaths = new List()
{
new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
}
};
Step 6: Set the new font for the txtaRange.
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";
Step 7: Convert the Doc to PDF.
document.SaveToFile("result.pdf", toPdf);
Step 8: Review converted PDF files.
System.Diagnostics.Process.Start("result.pdf");
Result screenshot:

Full Code Below:
Document document = new Document();
//Add the first secition
Section section = document.AddSection();
//Create a new paragraph and get the first paragraph
Paragraph paragraph
= section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();
//Append Text
String text
= "This paragraph is demo of text font and color. "
+ "The font name of this paragraph is Tahoma. "
+ "The font size of this paragraph is 20. "
+ "The under line style of this paragraph is DotDot. "
+ "The color of this paragraph is Blue. ";
TextRange txtRange = paragraph.AppendText(text);
//Import the font
ToPdfParameterList toPdf = new ToPdfParameterList()
{
PrivateFontPaths = new List<PrivateFontPath>()
{
new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
}
};
//Make use of the font.
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";
document.SaveToFile("result.pdf", toPdf);
System.Diagnostics.Process.Start("result.pdf");
To use different versions of PowerPoint document easier, Spire.Presentation enables to convert PowerPoint Presentation 97 – 2003 to PowerPoint Presentation 2007, 2010. Spire.Presentation supports to convert PPT to PPTX, from version 2.2.17, now it starts to load .pps format document and save to .ppsx format document in C#. This article will show you how to convert PPS to PPTX in C#.
Step 1: Create a presentation document.
Presentation presentation = new Presentation();
Step 2: Load the PPS file from disk.
presentation.LoadFromFile("sample.pps");
Step 3: Save the PPS document to PPTX file format.
presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010);
Step 4: Launch and view the resulted PPTX file.
System.Diagnostics.Process.Start("ToPPTX.pptx");
Full codes:
using Spire.Presentation;
namespace PPStoPPTX
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
//load the PPS file from disk
presentation.LoadFromFile("sample.pps");
//save the PPS document to PPTX file format
presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("ToPPTX.pptx");
}
}
}
Imports Spire.Presentation
Namespace PPStoPPTX
Class Program
Private Shared Sub Main(args As String())
Dim presentation As New Presentation()
'load the PPS file from disk
presentation.LoadFromFile("sample.pps")
'save the PPS document to PPTX file format
presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010)
System.Diagnostics.Process.Start("ToPPTX.pptx")
End Sub
End Class
End Namespace
The result PPTX document:

Set the outline and effects for shapes in PowerPoint files via Spire.Presentation
2015-03-19 08:05:12 Written by KoohjiOutline and effects for shapes can make the presentation of your PowerPoint files more attractive. This article talks about how to set the outline and effects for shapes via Spire.Presentation.
Step 1: Create a PowerPoint document.
Presentation ppt = new Presentation();
Step 2: Get the first slide
ISlide slide = ppt.Slides[0];
Step 3: Draw Rectangle shape on slide[0] with methord AppendShape();
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 50));
Step 4: Set outline color as red.
//Outline color shape.ShapeStyle.LineColor.Color = Color.Red;
Step 5: Add shadow effect and set parameters for it.
//Effect PresetShadow shadow = new PresetShadow(); shadow.Preset = PresetShadowValue.FrontRightPerspective; shadow.Distance = 10.0; shadow.Direction = 225.0f; shape.EffectDag.PresetShadowEffect = shadow;
Step 6: Change a Ellipse to add yellow outline with a glow effect:
Change step 4 and 5 as Code:
shape = slide.Shapes.AppendShape(ShapeType.Ellipse, new RectangleF(200, 100, 100, 100)); //Outline color shape.ShapeStyle.LineColor.Color = Color.Yellow; //Effect GlowEffect glow = new GlowEffect(); glow.ColorFormat.Color = Color.Purple; glow.Radius = 20.0; shape.EffectDag.GlowEffect = glow;
Step 7: Save and review.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("Sample.PPTx");
Here is the screen shot:

In some circumstance where we need to create a copy of the existing pages in our PDF document instead of copying the entire file, in particular, if we have to create hundreds copies of a certain page, it can be tedious to copy the page one after another. This article demonstrates a solution for how to duplicate a page in a PDF document and create multiple copies at a time using Spire.PDF.
In this example, I prepare a sample PDF file that only contains one page and eventually I’ll create ten copies of this page in the same document. Main method would be as follows:
Code Snippet:
Step 1: Create a new PDF document and load the sample file.
PdfDocument pdf = new PdfDocument("Sample.pdf");
Step 2: Get the first page from PDF, get the size of the page. Create a new instance of Pdf Template object based on the content and appearance of the first page.
PdfPageBase page = pdf.Pages[0]; SizeF size = page.Size; PdfTemplate template = page.CreateTemplate();
Step 3: Create a new PDF page with the method Pages.Add() based on the size of the first page, draw the template on the new page at the specified location. Use a for loops to get more copies of this page.
for (int i = 0; i < 10; i++)
{
page = pdf.Pages.Add(size, new PdfMargins(0));
page.Canvas.DrawTemplate(template, new PointF(0, 0));
}
Step 4: Save the file.
pdf.SaveToFile("Result.pdf");
Output:
Ten copies of the first page have been created in the sample PDF document.

Full Code:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace DuplicatePage
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument("Sample.pdf");
PdfPageBase page = pdf.Pages[0];
SizeF size = page.Size;
PdfTemplate template = page.CreateTemplate();
for (int i = 0; i < 10; i++)
{
page = pdf.Pages.Add(size, new PdfMargins(0));
page.Canvas.DrawTemplate(template, new PointF(0, 0));
}
pdf.SaveToFile("Result.pdf");
}
}
}
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing
Namespace DuplicatePage
Class Program
Private Shared Sub Main(args As String())
Dim pdf As New PdfDocument("Sample.pdf")
Dim page As PdfPageBase = pdf.Pages(0)
Dim size As SizeF = page.Size
Dim template As PdfTemplate = page.CreateTemplate()
For i As Integer = 0 To 9
page = pdf.Pages.Add(size, New PdfMargins(0))
page.Canvas.DrawTemplate(template, New PointF(0, 0))
Next
pdf.SaveToFile("Result.pdf")
End Sub
End Class
End Namespace
How to Apply Conditional Formatting to a Data Range in C#
2015-03-13 07:22:54 Written by AdministratorConditional formatting in Microsoft Excel has a number of presets that enables users to apply predefined formatting such as colors, icons and data bars, to a range of cells based on the value of the cell or the value of a formula. Conditional formatting usually reveals the data trends or highlights the data that meets one or more formulas.
In this article, I made an example to explain how these conditional formatting types can be achieved programmatically using Spire.XLS in C#. First of all, let's see the worksheet that contains a group of data in selected range as below, we’d like see which cells’ value is bigger than 800. In order to quickly figure out similar things like this, we can create a conditional formatting rule by formula: “If the value is bigger than 800, color the cell with Red” to highlight the qualified cells.

Code Snippet for Creating Conditional Formatting Rules:
Step 1: Create a worksheet and insert data to cell range from A1 to C4.
Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; sheet.Range["A1"].NumberValue = 582; sheet.Range["A2"].NumberValue = 234; sheet.Range["A3"].NumberValue = 314; sheet.Range["A4"].NumberValue = 50; sheet.Range["B1"].NumberValue = 150; sheet.Range["B2"].NumberValue = 894; sheet.Range["B3"].NumberValue = 560; sheet.Range["B4"].NumberValue = 900; sheet.Range["C1"].NumberValue = 134; sheet.Range["C2"].NumberValue = 700; sheet.Range["C3"].NumberValue = 920; sheet.Range["C4"].NumberValue = 450; sheet.AllocatedRange.RowHeight = 15; sheet.AllocatedRange.ColumnWidth = 17;
Step 2: To highlight cells based on their values, we create two conditional formatting rules: one for cells greater than 800, and another for cells less than 300.
XlsConditionalFormats xcfs1 = sheet.ConditionalFormats.Add(); xcfs1.AddRange(sheet.AllocatedRange); IConditionalFormat cf1 = xcfs1.AddCondition(); cf1.FormatType = ConditionalFormatType.CellValue; cf1.FirstFormula = "800"; cf1.Operator = ComparisonOperatorType.Greater; cf1.FontColor = Color.Red; cf1.BackColor = Color.LightSalmon; Apply Data Bars: IConditionalFormat cf3 = xcfs1.AddCondition(); cf3.FormatType = ConditionalFormatType.DataBar; cf3.DataBar.BarColor = Color.CadetBlue; Apply Icon Sets: IConditionalFormat cf4 = xcfs1.AddCondition(); cf4.FormatType = ConditionalFormatType.IconSet; Apply Color Scales: IConditionalFormat cf5 = xcfs1.AddCondition(); cf5.FormatType = ConditionalFormatType.ColorScale;
Step 3: Save and launch the file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("sample.xlsx");
Result:
The cells with value bigger than 800 and smaller than 300, have been highlighted with defined text color and background color.

Apply the Other Three Conditional Formatting Types:
Spire.XLS also supports applying some other conditional formatting types which were predefined in MS Excel. Use the following code snippets to get more formatting effects.
Apply Data Bars:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.DataBar; format.DataBar.BarColor = Color.CadetBlue;

Apply Icon Sets:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.IconSet;

Apply Color Scales:
ConditionalFormatWrapper format = sheet.AllocatedRange.ConditionalFormats.AddCondition(); format.FormatType = ConditionalFormatType.ColorScale;

Full Code:
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.Collections;
using System.Drawing;
namespace ApplyConditionalFormatting
{
class Program
{
static void Main(string[] args)
{
// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
// Populate sample data in cells A1:C4
sheet.Range["A1"].NumberValue = 582;
sheet.Range["A2"].NumberValue = 234;
sheet.Range["A3"].NumberValue = 314;
sheet.Range["A4"].NumberValue = 50;
sheet.Range["B1"].NumberValue = 150;
sheet.Range["B2"].NumberValue = 894;
sheet.Range["B3"].NumberValue = 560;
sheet.Range["B4"].NumberValue = 900;
sheet.Range["C1"].NumberValue = 134;
sheet.Range["C2"].NumberValue = 700;
sheet.Range["C3"].NumberValue = 920;
sheet.Range["C4"].NumberValue = 450;
sheet.AllocatedRange.RowHeight = 15;
sheet.AllocatedRange.ColumnWidth = 17;
// Create a conditional formatting rule set applied to the entire used range
XlsConditionalFormats xcfs1 = sheet.ConditionalFormats.Add();
xcfs1.AddRange(sheet.AllocatedRange);
// Rule 1: Highlight cells with values greater than 800 in red text and light salmon background
IConditionalFormat cf1 = xcfs1.AddCondition();
cf1.FormatType = ConditionalFormatType.CellValue;
cf1.FirstFormula = "800";
cf1.Operator = ComparisonOperatorType.Greater;
cf1.FontColor = Color.Red;
cf1.BackColor = Color.LightSalmon;
// Rule 2: Highlight cells with values less than 300 in green text and light blue background
IConditionalFormat cf2 = xcfs1.AddCondition();
cf2.FormatType = ConditionalFormatType.CellValue;
cf2.FirstFormula = "300";
cf2.Operator = ComparisonOperatorType.Less;
cf2.FontColor = Color.Green;
cf2.BackColor = Color.LightBlue;
//// Rule 3: Add data bars
//IConditionalFormat cf3 = xcfs1.AddCondition();
//cf3.FormatType = ConditionalFormatType.DataBar;
//cf3.DataBar.BarColor = Color.CadetBlue;
//// Rule 4: Apply icon set
//IConditionalFormat cf4 = xcfs1.AddCondition();
//cf4.FormatType = ConditionalFormatType.IconSet;
//// Rule 5: Apply color scale
//IConditionalFormat cf5 = xcfs1.AddCondition();
//cf5.FormatType = ConditionalFormatType.ColorScale;
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("sample.xlsx");
}
}
}
In the previous topic, we discussed about how to insert hyperlink into PowerPoint presentation. In this topic, we will show you how to remove the hyperlink on a slide in the presentation by using the Spire.Presentation in C#.
Firstly, view the hyperlinks on a slide that we need to remove later.

Here comes to the steps of how to remove the hyperlinks in the PowerPoint presentation in C#.
Step 1: Create Presentation instance and load file.
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
Step 2: Get the shape and its text with hyperlink.
IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape;
Step 3: Set the ClickAction property into null to remove the hyperlink.
shape.TextFrame.TextRange.ClickAction = null;
Step 4: Save the document to file.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
Effective screenshot after removing the first hyperlink:

Full codes:
using Spire.Presentation;
namespace RemoveHyperlink
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
IAutoShape shape = ppt.Slides[0].Shapes[1] as IAutoShape;
shape.TextFrame.TextRange.ClickAction = null;
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
}
}
}
Adding an image in table cell can make your PPT files more different. Spire.Presentation allows developers add images to table cells. Here we introduce an example to add an image to a table cell in PPT.
Step 1: Create a new PPT document instance.
Presentation presentation = new Presentation();
Step 2: Call AppendTable() method to create a table and set the table style.
ISlide slide = presentation.Slides[0];
Double[] widths = new double[] { 100, 100};
Double[] heights = new double[] { 100, 100};
ITable table = presentation.Slides[0].Shapes.AppendTable(100, 80, widths, heights);
table.StylePreset = TableStylePreset.LightStyle1Accent2;
Step 3: Use table[0, 0].FillFormat.PictureFill.Picture.EmbedImage to embed the image to the cell. The FillType can be changed.
IImageData imgData = presentation.Images.Append(Image.FromFile("1.jpg"));
table[0, 0].FillFormat.FillType = FillFormatType.Picture;
table[0, 0].FillFormat.PictureFill.Picture.EmbedImage = imgData;
table[0, 0].FillFormat.PictureFill.FillType = PictureFillType.Stretch;
Step 4: Save and review.
presentation.SaveToFile("table.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("table.pptx");
Here is the screenshot:

Layout of PPT concerns visual effect directly. PPT Viewer may have different feelings and thoughts such as tense, confused or anxious about different layouts. We can make our PPT files show main information and weaken minor information. This article will show how to set the layout for your slide via Spire.Presentation. Here are the steps:
Step 1: Create a PPT document.
Presentation ppt = new Presentation();
Step2: Set the layout for slide. Spire.Presentation offers 11 kinds of layout just as Microsoft PowerPoint supports.
ISlide slide = ppt.Slides.Append(SlideLayoutType.Title);

Step 3: Add content for Title and Text.
IAutoShape shape = slide.Shapes[0] as IAutoShape; shape.TextFrame.Text = "Hello Wolrd! –> This is title"; shape = slide.Shapes[1] as IAutoShape; shape.TextFrame.Text = "E-iceblue Support Team -> This is content";
Step 4: Save and review.
ppt.SaveToFile("Result.PPTx", FileFormat.PPTx2010);
System.Diagnostics.Process.Start("Result.PPTx");
Here is the result:

Then change another layout (Picture With Caption) to show: PictureAndCaption
Use function AppendEmbedImage to add image, and notice the order of the shape in PictureAndCaption is Shapes[1], Shapes[0] and Shapes[2].
Full code:
using Spire.Presentation;
namespace SetLayout
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ISlide slide = ppt.Slides.Append(SlideLayoutType.PictureAndCaption);
string ImageFile2 = "1.jpg";
IAutoShape shape0 = slide.Shapes[1] as IAutoShape;
slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, shape0.Frame.Rectangle);
IAutoShape shape = slide.Shapes[0] as IAutoShape;
shape.TextFrame.Text = "Title - Cattle back mountain";
IAutoShape shape2 = slide.Shapes[2] as IAutoShape;
shape2.TextFrame.Text = " Text content - Got name because it's slender ridge seems cow back";
ppt.SaveToFile("Sample.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("Sample.PPTx");
}
}
}
Result:

PDF attachments allow users to see more details on a particular point by visiting attachments inside the PDF. Basically, there are two types of attachments in PDF: document level attachment and annotation attachment. Below are the differences between them.
- Document Level Attachment (represented by PdfAttachment class): A file attached to a PDF at the document level won't appear on a page, but only appear in the PDF reader's "Attachments" panel.
- Annotation Attachment (represented by PdfAttachmentAnnotation class): A file that is attached to a specific position of a page. Annotation attachments are shown as a paper clip icon on the page; reviewers can double-click the icon to open the file.
In this article, you will learn how to extract these two kinds of attachments from a PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Extract Attachments from PDF in C# and VB.NET
The document level attachments of a PDF document can be obtained through PdfDocument.Attachments property. The following steps illustrate how to extract all document level attachments from a PDF document and save them to a local folder.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Get the attachment collection from the document through PdfDocument.Attachments property.
- Get the data of a specific attachment through PdfAttachment.Data property.
- Write the data to a file and save to a specified folder.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Attachments;
using System.Net.Mail;
namespace ExtractAttachments
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file that contains attachments
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Attachments.pdf");
//Get the attachment collection of the PDF document
PdfAttachmentCollection attachments = doc.Attachments;
//Specific output folder path
string outputFolder = "C:\\Users\\Administrator\\Desktop\\output\\";
//Loop through the collection
for (int i = 0; i < attachments.Count; i++)
{
//Write attachment to a file
File.WriteAllBytes(outputFolder + attachments[i].FileName, attachments[i].Data);
}
}
}
}

Extract Annotation Attachments from PDF in C# and VB.NET
Annotation attachment is a page-based element. To get annotations from a specific page, use PdfPageBase.AnnotationsWidget property. After that, you’ll need to determine if a specific annotation is an annotation attachment. The follows are the steps to extract annotation attachments from a PDF document and save them to a local folder.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Get a specific page from the document through PdfDocument.Pages[] property.
- Get the annotation collection from the page through PdfPageBase.AnnotationsWidget property.
- Determine if a specific annotation is an instance of PdfAttachmentAnnotationWidget. If yes, write the annotation attachment to a file and save it to a specified folder.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Annotations;
namespace ExtractAnnotationAttachments
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file that contains attachments
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\AnnotationAttachments.pdf");
//Specific output folder path
string outputFolder = "C:\\Users\\Administrator\\Desktop\\Output\\";
//Loop through the pages
for (int i = 0; i < doc.Pages.Count; i++)
{
//Get the annotation collection
PdfAnnotationCollection collection = doc.Pages[i].Annotations;
//Loop through the annotations
for (int j = 0; j < collection.Count; j++)
{
//Determine if an annotation is an instance of PdfAttachmentAnnotationWidget
if (collection[j] is PdfAttachmentAnnotationWidget)
{
//Write annotation attachment to a file
PdfAttachmentAnnotationWidget attachmentAnnotation = (PdfAttachmentAnnotationWidget)collection[j];
String fileName = Path.GetFileName(attachmentAnnotation.FileName);
File.WriteAllBytes(outputFolder + fileName, attachmentAnnotation.Data);
}
}
}
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Delete Text Boxes in PowerPoint with C# (Including Empty Ones)
2015-02-16 08:27:07 Written by Koohji
Deleting text boxes in a PowerPoint presentation is a crucial step when cleaning up templates or removing unwanted content—but doing it manually can be time-consuming, especially when dealing with multiple slides. If you're looking for how to delete text boxes in PowerPoint using C#, you're in the right place. This guide covers everything from deleting a specific text box to removing empty ones or clearing all text boxes on a slide—providing practical, code-based solutions to streamline your workflow.
- Before We Start: Install PowerPoint Library
- Delete Specific Text Boxes in PowerPoint Slides
- Delete Empty Text Boxes in PowerPoint Slides
- Delete All Text Boxes from a PowerPoint Slide
- Conclusion
- FAQs
Before We Start: Install PowerPoint Library
Before we dive into the main content, let’s first set up the required tools. In this tutorial, we’ll be using Spire.Presentation for .NET to demonstrate how to delete text boxes in a PowerPoint presentation. This is a professional third-party PowerPoint library that allows you to manipulate slide elements—such as adding or deleting text boxes—without relying on Microsoft Office.
To install the library, you have two options:
- Download Spire.Presentation and install it manually from the official website.
- Use NuGet Package Manager, which is the recommended approach for most Visual Studio users. Simply run the following command in the Package Manager Console:
PM> Install-Package Spire.Presentation
This will automatically download and add the library to your project. A free version is available for learning or evaluation, with limited features but no time restrictions.
How to Delete a Specific Text Box in PowerPoint Slides Using C#
When you only need to remove or replace a small part of the slide content, it's best to precisely target the specific text box you want to delete. With the help of Spire.Presentation, you can easily delete a specific text box from a PowerPoint presentation. The basic workflow includes: loading the PowerPoint file, locating the slide, identifying the target text box, and removing it.
We’ll first look at the complete code, then break it down step by step.
Code Example – Remove "Text Box 1" from Slide 2:
using Spire.Presentation;
namespace RemoveTextbox
{
class Program
{
static void Main(string[] args)
{
// Create a Presentation instance and load a PowerPoint file
Presentation ppt = new Presentation("/input/pre1.pptx", FileFormat.Pptx2010);
// Get the second slide
ISlide slide = ppt.Slides[1];
// Loop through all shapes on the slide
for (int i = 0; i < slide.Shapes.Count;)
{
IAutoShape shape = slide.Shapes[i] as IAutoShape;
// Check if the shape is a text box and contains the specified text
if (shape != null && shape.IsTextBox && shape.TextFrame.Text.Equals("Text Box 1"))
{
// Remove the text box
slide.Shapes.Remove(shape);
}
else
{
i++;
}
}
// Save the modified presentation
string outputPath = "/output/Deletespecifictextbox.pptx";
ppt.SaveToFile(outputPath, FileFormat.Pptx2010);
System.Diagnostics.Process.Start(outputPath);
}
}
}
Text boxes removing result preview: 
Key steps explained:
- Create a Presentation class and load a PowerPoint file.
- Get a slide with Presentation.Slides[] property.
- Loop through shapes on the slide and check if they are IAutoShape and contain the target text.
- If it is, delete the text box using ISlide.Shapes.Remove() method.
After cleaning up empty or unwanted text boxes, you may want to add new content dynamically. Learn how to add a paragraph to a PowerPoint slide using C# in this related tutorial.
How to Delete Empty Text Boxes in PowerPoint with C#
When working with PowerPoint presentations, deleting empty text boxes is a common requirement. These unused placeholders can clutter your slides and negatively affect the overall layout. Cleaning them up is an important step in creating a polished and professional presentation.
Code example - Delete all text boxes on the 3rd slide from a Microsoft PowerPoint Presentation:
using Spire.Presentation;
namespace RemoveEmptyTextboxes
{
class Program
{
static void Main(string[] args)
{
// Load the PowerPoint presentation
Presentation ppt = new Presentation("/input/pre1.pptx", FileFormat.Pptx2010);
// Access the third slide (index starts from 0)
ISlide slide = ppt.Slides[2];
// Iterate through all shapes on the slide
for (int i = 0; i < slide.Shapes.Count;)
{
IAutoShape shape = slide.Shapes[i] as IAutoShape;
// Check if the shape is a text box and its text is null, empty, or whitespace
if (shape != null && shape.IsTextBox && string.IsNullOrWhiteSpace(shape.TextFrame.Text))
{
// Remove empty text box
slide.Shapes.Remove(shape);
}
else
{
i++;
}
}
// Save the updated presentation
string outputPath = "/output/RemoveEmptyTextboxes.pptx";
ppt.SaveToFile(outputPath, FileFormat.Pptx2010);
}
}
}
Text boxes removing result preview: 
Key steps explained:
- Load a PowerPoint file and get a slide.
- Iterate through shapes on the slide and check if they are text boxes and empty.
- Delete all empty text boxes through ISlide.Shapes.Remove() method.
Tip: If you want to delete all empty text boxes from the entire PowerPoint presentation, simply loop through each slide instead of targeting a single one. You can do this by iterating through presentation.Slides and checking each shape on every slide.
foreach (ISlide slide in presentation.Slides)
{
for (int i = slide.Shapes.Count - 1; i >= 0; i--)
{
IShape shape = slide.Shapes[i];
if (shape is IAutoShape autoShape && string.IsNullOrWhiteSpace(autoShape.TextFrame.Text))
{
slide.Shapes.Remove(shape);
}
}
}
How to Delete All Text Boxes in PowerPoint Slides Using C#
Now let’s move on to the final section—deleting all text boxes from a slide, including both empty and non-empty ones. This approach is even simpler than the previous examples. You just need to loop through the shapes on a slide, check whether each shape is an IAutoShape, and remove it using the ISlide.Shapes.Remove(shape) method. We won’t break down the steps here, as the code is self-explanatory. Just copy the snippet below, update the file path and other details as needed, and you're good to go.
Code example - Delete all text boxes on the second slide:
namespace RemoveTextboxes
{
internal class Program
{
static void Main(string[] args)
{
// Create a new Presentation object
Presentation ppt = new Presentation("/input/pre1.pptx", FileFormat.Pptx2010);
// Get the second slide and loop through its shapes
ISlide slide = ppt.Slides[1];
for (int i = 0; i < slide.Shapes.Count;)
{
// Check if the shape is an AutoShape and remove it
IAutoShape shape = slide.Shapes[i] as IAutoShape;
slide.Shapes.Remove(shape);
}
// Save the updated presentation
ppt.SaveToFile("/output/deletetextbox.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("Result.pptx");
}
}
}
Text boxes removing result preview: 
The Conclusion
The page explored how to delete text boxes in PowerPoint using C#. Whether you’re removing a specific text box, deleting empty text boxes, or clearing all text boxes, the process becomes simple and straightforward with the help of Spire.Presentation for .NET. If you’re interested in this PowerPoint library, you can request a free 30-day trial license to explore its full capabilities.
FAQs about Deleting Text Boxes in PowerPoint
1. Why can't I delete a text box in PowerPoint?
There are a few possible reasons: the text box might be part of the slide master, grouped with other elements, or accidentally locked. If you're automating PowerPoint using C#, make sure you correctly access the Shapes collection of the target slide and identify the right shape type (e.g., IAutoShape) before attempting to delete it.
2. How do I delete a text box from a PowerPoint slide using C#?
You can access the slide using Presentation.Slides[index], loop through the Shapes collection, find the text box (typically an IAutoShape), and remove it with ISlide.Shapes.Remove(shape). Full code examples are provided in this article for deleting specific, empty, or all text boxes.