Working With Spire.Presentation

In this post we are going to quick overview on Spire.Presentation using Visual Studio. First we need to download & install it to our system.

Introduction

Spire.Presentation is a professional PowerPoint® compatible component that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET) platform. As an independent PowerPoint .NET component, Spire.Presentation for .NET doesn’t need Microsoft PowerPoint installed on the machine.

Spire.Presentation for .NET support PPT, PPS, PPTX and PPSX presentation formats. It provides functions such as managing text, image, shapes, tables, animations, audio and video on slides. It also support exporting presentation slides to EMF, JPG, TIFF, PDF format etc.

Child categories

  • Conversion
  • Paragraph and Text
  • Document Operation
  • Image and Shapes
  • Table
  • Chart
  • Audio and Video
  • Comment and Note
  • Hyperlink
  • Security
  • Watermark
  • SmartArt
  • Print
  • Other

Get more details from here

Let’s create a sample application in Windows Form and have a look on how it work actually.

Install it from NuGet

Search for Spire packages here. Now go to solution explorer open the form add button like below image.

DoubleClick on button and paste the below code snippet to generate a ‘hello world’ ppt result.

//create PPT document
Presentation presentation = new Presentation();
//add new shape to PPT document           
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle,
                    new RectangleF(0, 50, 200, 50));
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
//add text to shape
shape.AppendTextFrame("Hello World!");
//set the Font fill style of text  
TextRange textRange = shape.TextFrame.TextRange;
textRange.Fill.FillType = Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.Black;
textRange.LatinFont = new TextFont("Arial Black");
//save the document
presentation.SaveToFile("hello.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("hello.pptx");

Add Smart Art DoubleClick on Spire.Presentation Smartart button and paste the below code snippet to generate a ‘Smart Art’ ppt result.

//add a smartart
Presentation pres = new Presentation();
Spire.Presentation.Diagrams.ISmartArt sa = pres.Slides[0].Shapes.AppendSmartArt(20, 40, 300, 300, Spire.Presentation.Diagrams.SmartArtLayoutType.Gear);

//set type and color of smartart
sa.Style = Spire.Presentation.Diagrams.SmartArtStyleType.SubtleEffect;
sa.ColorStyle = Spire.Presentation.Diagrams.SmartArtColorType.GradientLoopAccent3;

//remove all shapes
foreach (object a in sa.Nodes)
    sa.Nodes.RemoveNode(0);

//add two custom shapes with text
Spire.Presentation.Diagrams.ISmartArtNode node = sa.Nodes.AddNode();
sa.Nodes[0].TextFrame.Text = "aa";
node = sa.Nodes.AddNode();
node.TextFrame.Text = "bb";
node.TextFrame.TextRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
node.TextFrame.TextRange.Fill.SolidColor.KnownColor = KnownColors.Black;

//save and launch the file
pres.SaveToFile("SmartArtTest1.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("SmartArtTest1.pptx");

Get more details from here on how to create a table programmatically using Spire.Presentation for .NET

OutPut: Finally run the application, the application will generate a ppt file with output text.

Source Code: I’ve uploaded the full source code to download/clone , Hope this will help 🙂

Author:

Since March 2011, have 8+ years of professional experience on software development, currently working as Senior Software Engineer at s3 Innovate Pte Ltd.

One thought on “Working With Spire.Presentation”

Leave a Reply