Knowledgebase (2311)
Children categories
PPT file format is a vivid and explicit way to present your stuff. PPT file can be very beautiful and powerful. And text is a basic element that PPT supports. Spire.Presentation is a powerful .NET component specially designed for developers. It enables developers to manipulate PPT files easily and flexibly. In this document, I will introduce you how to add a paragraph to PPT file using Spire.Presentation.
Step 1. Create a PPT document.
Presentation presentation = new Presentation();
Step 2. Add a new shape to the document.
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 450, 150)); shape.Fill.FillType = FillFormatType.None; shape.ShapeStyle.LineColor.Color = Color.White;
Shape represents a TextBox in PPT document.
Step 3. Add some text to the shape.
shape.TextFrame.Text = "This powerful component suite contains the most up-to-date versions of all .NET WPF Silverlight components offered by E-iceblue.";
These will form a new paragraph.
Step 4. Set the alignment of the paragraph.
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
Step 5. Set the indent of the paragraph.
shape.TextFrame.Paragraphs[0].Indent = 25*2;
Step 6. Set the line spacing of the paragraph.
shape.TextFrame.Paragraphs[0].LineSpacing = 250;
Step 7. Save the document.
presentation.SaveToFile("para.pptx", FileFormat.Pptx2010);
Full code:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddParagh
{
class Program
{
static void Main(string[] args)
{
//create PPT document
Presentation presentation = new Presentation();
//set background Image
string ImageFile = "bg.png";
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
//append new shape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 450, 150));
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
//set the alignment
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
//set the indent
shape.TextFrame.Paragraphs[0].Indent = 50;
//set the linespacing
shape.TextFrame.Paragraphs[0].LineSpacing = 150;
shape.TextFrame.Text = "This powerful component suite contains the most up-to-date versions of all .NET WPF Silverlight components offered by E-iceblue.";
//set the Font
shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;
//save the document
presentation.SaveToFile("para.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("para.pptx");
}
}
}
'create PPT document
Dim presentation As New Presentation()
'set background Image
Dim ImageFile As String = "bg.png"
Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height)
presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect)
presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite
'append new shape
Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 450, 150))
shape.Fill.FillType = FillFormatType.None
shape.ShapeStyle.LineColor.Color = Color.White
'set the alignment
shape.TextFrame.Paragraphs(0).Alignment = TextAlignmentType.Left
'set the indent
shape.TextFrame.Paragraphs(0).Indent = 50
'set the linespacing
shape.TextFrame.Paragraphs(0).LineSpacing = 150
shape.TextFrame.Text = "This powerful component suite contains the most up-to-date versions of all .NET WPF Silverlight components offered by E-iceblue."
'set the Font
shape.TextFrame.Paragraphs(0).TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold")
shape.TextFrame.Paragraphs(0).TextRanges(0).Fill.FillType = FillFormatType.Solid
shape.TextFrame.Paragraphs(0).TextRanges(0).Fill.SolidColor.Color = Color.Black
'save the document
presentation.SaveToFile("para.pptx", FileFormat.Pptx2010)
System.Diagnostics.Process.Start("para.pptx")
Screenshot:

A hyperlink is a clickable element, typically embedded within text or images, which allows users to navigate and access different webpages, documents, or resources. By adding hyperlinks in a PowerPoint presentation, users are able to easily visit related content while viewing or showing the slides, enhancing convenience during the presentation. In this article, we will show you how to add hyperlink to PowerPoint Presentation programmatically by using Spire.Presentation for .NET.
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add Hyperlink to Text on Slide
Spire.Presentation for .NET allows users to insert hyperlink to text on slides easily by using TextRange.ClickAction.Address property. The following are detailed steps.
- Create a new PowerPoint presentation.
- Load a PowerPoint file using Presentation.LoadFromFile() method.
- Get the first slide using Presentation.Slides[] property.
- Add a rectangle shape to the slide by using ISlide.Shapes.AppendShape() method.
- Remove the default paragraphs in the shape.
- Create a TextParagraph instance to represent a text paragraph.
- Create a TextRange instance to represent a text range and set link address for it by TextRange.ClickAction.Address property.
- Create an another TextRange instance to represent the rest of the text.
- Append text ranges to paragraph using TextParagraph.TextRanges.Append() method.
- Append the paragraph to the shape using IAutoShape.TextFrame.Paragraphs.Append() method.
- Loop through all text ranges in each paragraph and set font for them.
- Save the result file using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace Hyperlink
{
internal class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation presentation = new Presentation();
//Load the PowerPoint file
presentation.LoadFromFile("sample.pptx", FileFormat.Pptx2010);
//Get the first slide of the presentation
ISlide slide = presentation.Slides[0];
//Add a shape to the slide
RectangleF rec = new RectangleF(presentation.SlideSize.Size.Width / 2 - 120, 200, 500, 150);
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, rec);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
//Remove the default paragraphs in the shape
shape.TextFrame.Paragraphs.Clear();
//Create a TextParagraph instance
TextParagraph para = new TextParagraph();
//Create a TextRange instance
TextRange tr = new TextRange("Spire.Presentation for .NET");
//Set a hyperlink address for the text range
tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";
//Append the text range to the paragraph
para.TextRanges.Append(tr);
//Create a TextRange instance
tr = new TextRange("is a professional PowerPoint® compatible API that enables developers to create, read, modify, convert and Print PowerPoint documents on any .NET platform."
+"As an independent PowerPoint .NET API, Spire.Presentation for .NET doesn't need Microsoft PowerPoint to be installed on machines.");
//Append the text range to the paragraph
para.TextRanges.Append(tr);
//Append the paragraph to the shape
shape.TextFrame.Paragraphs.Append(para);
//Loop through the paragraphs in the shape
foreach (TextParagraph textPara in shape.TextFrame.Paragraphs)
{
if (!string.IsNullOrEmpty(textPara.Text))
{
//Loop through the text ranges in each paragraph
foreach (TextRange textRange in textPara.TextRanges)
{
//Set font
textRange.LatinFont = new TextFont("Calibri");
textRange.FontHeight = 24;
textRange.Fill.FillType = FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.Black;
}
}
}
//Save the presentation
presentation.SaveToFile("TextHyperlink.pptx", FileFormat.Pptx2013);
presentation.Dispose();
}
}
}

Add Hyperlink to Image on Slide
Spire.Presentation for .NET also supports adding a hyperlink to an image. You can create a hyperlink by using ClickHyperlink class and then add the hyperlink to the image using the IEmbedImage.Click property. The related steps are as follows.
- Create a new PowerPoint presentation.
- Load a PowerPoint file using Presentation.LoadFromFile() method.
- Get the second slide by using Presentation.Slides[] property.
- Add a image to the slide using ISlide.Shapes.AppendEmbedImage() method.
- Create a ClickHyperlink object and append the hyperlink to added image using IEmbedImage.Click property.
- Save the result file using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
using System.Drawing;
namespace ImageHyperlink
{
class Program
{
static void Main(string[] args)
{
//Initialize an object of Presentation class
Presentation presentation = new Presentation();
//Load the PowerPoint file
presentation.LoadFromFile("TextHyperlink.pptx", FileFormat.Pptx2010);
//Get the second slide of the presentation
ISlide slide = presentation.Slides[1];
//Add a image to slide
RectangleF rect = new RectangleF(100, 50, 150, 150);
IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);
//Add hyperlink to image
ClickHyperlink hyperlink = new ClickHyperlink("http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html");
image.Click = hyperlink;
//Save the result file
presentation.SaveToFile("ImageHyperlink.pptx", FileFormat.Pptx2010);
presentation.Dispose();
}
}
}

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.
PPT is the file format used by Microsoft PowerPoint Presentation 97 - 2003, while PPTX is created by PowerPoint Presentation 2007, 2010. PPTX file format enjoys the advantages of smaller size, higher security, and higher integration with other file formats. But the Microsoft Office version under 2007 cannot open PPTX PowerPoint presentation directly. This article will show you how to convert PPT file format to PPTX in C# with only three lines of code.
Make sure Spire.Presentation for .NET has been installed correctly and then add Spire.Presentation.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Presentation\Bin\NET4.0\ Spire. Presentation.dll". Here comes to the details of how to output PPT to PPTX:
Step 1: Create a presentation document.
Presentation presentation = new Presentation();
Step 2: Load the PPT file from disk.
presentation.LoadFromFile(@"..\..\..\..\..\..\Data\sample4.ppt");
Step 3: Save the PPT document to PPTX file format.
presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010);
Step4: Launch and view the resulted PPTX file.
System.Diagnostics.Process.Start("ToPPTX.pptx");
Full codes:
namespace Spire.Presentation.Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnRun_Click(object sender, EventArgs e)
{
//create PPT document
Presentation presentation = new Presentation();
//load the PPT file from disk
presentation.LoadFromFile(@"..\..\..\..\..\..\Data\sample4.ppt");
//save the PPT document to PPTX file format
presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("ToPPTX.pptx");
}
}
}
Target screenshot:
