New Library Creates and Manipulates PowerPoint Files

With the release of Essential Studio 2015 Volume 1, Syncfusion introduced the beta version of Essential Presentation, a new .NET library that can read, write, convert, and create raster images from Microsoft PowerPoint files. It provides a rich object model similar to Syncfusion’s file format libraries: XlsIO, DocIO, and PDF. This library can be used with Windows Forms, WPF, ASP.NET, and ASP.NET MVC applications. As it does not depend on Microsoft Office or any other external software, this library can be used on the server side without any difficulty. Keep in mind that this version of Essential Presentation supports only PowerPoint 2007-2013 (.pptx) files.

Key features of Essential Presentation

  • Opens and saves PowerPoint (.pptx) files from and to streams.
  • Sends output to a client browser.
  • Accesses and modifies a PowerPoint presentation’s document properties.
  • Creates and manipulates charts within a PowerPoint file.
  • Creates and manipulates bulleted lists, numbered lists, tables, shapes, pictures, etc.
  • Exports a single slide or an entire PowerPoint presentation to PDF.
  • Renders a slide or an entire presentation as an image.

Note: Since this version of Essential Presentation is in beta, it does not have some features found in Microsoft PowerPoint such as WordArt, SmartArt, slide notes, master-slide editing, animations, transitions, comments, headers, footers, OLE objects, handouts, equations, and built-in themes.

How can I get started?

In order to create and modify a PowerPoint presentation, you need to know how the elements are organized in Essential Presentation’s document object model (DOM). The following figure illustrates this DOM.


DOM of Essential Presentation

  • IPresentation – An instance of IPresentation represents an entire PowerPoint presentation file. It is the root element in Essential Presentation’s DOM. This presentation instance contains the slide collections present in the PowerPoint presentation file.
  • ISlide – An instance of ISlide represents a single slide within a PowerPoint presentation, which in turn contains a collection of shapes. All the elements present within a slide are enclosed in a shape.
  • IOfficeChart – IOfficeChart represents a chart present within a slide. Through this instance, you can customize the chart.
  • ITable – An instance of ITable represents a table within a slide. A table instance contains a collection of rows.
  • IRow – An IRow instance represents a single row in a table. Each row contains a collection of cells.
  • ICell – An ICell instance represents a single cell within a row. A cell contains an instance of ITextBody, through which you can to add or modify the textual content of a slide.
  • ITextBody – ITextBody represents a container for textual content. It can contain a collection of paragraphs.
  • IParagraph – An IParagraph instance represents a paragraph. Paragraphs can only be added into text boxes and auto-shapes. A paragraph contains a collection of text parts.
  • ITextPart – A text part is similar to <span> in HTML. An instance of ITextPart holds textual content of similar character-level formatting.
  • IPicture – The IPicture interface represents a picture or image in a slide.

We have published resources explaining in detail on how to get started using the presentation library:

The following code snippet creates a simple PowerPoint presentation with two slides.

[C#]

 

using Syncfusion.Presentation;

 

namespace HelloWorld

{

    class Program

    {

        static void Main(string[] args)

        {

            //Create an instance of IPresentation, which is the DOM’s root element.

            IPresentation presentation = Presentation.Create();

            //User-defined method calls to create slides in file.

            CreateSlide1(presentation);

            CreateSlide2(presentation);

            //Save the created .pptx file.

            presentation.Save(@"HelloWorld.pptx");

            //Close the presentation instance.

            presentation.Close();

        }

 

        private  static void CreateSlide1(IPresentation presentation)

        {

            //Create a slide with a blank layout.

            ISlide slide1 = presentation.Slides.Add(SlideLayoutType.Blank);

            //Add a text box for adding the title of the presentation.

            IShape titleShape = slide1.AddTextBox(120.25, 88.56, 720, 187.92);

            //Access the text body and set its vertical alignment as bottom.

            ITextBody textBody = titleShape.TextBody;

            textBody.VerticalAlignment = VerticalAlignmentType.Bottom;

            //Add a new paragraph into the text-box body and set its horizontal alignment as center.

            IParagraph paragraph = textBody.AddParagraph();

            paragraph.HorizontalAlignment = HorizontalAlignmentType.Center;

            //Create an instance of a text part and set the text content.

            ITextPart textPart1 = paragraph.AddTextPart();

            textPart1.Text = "Hello Presentation";

            //Specify font name and font size for the text content.

            textPart1.Font.FontName = "Calibri Light";

            textPart1.Font.FontSize = 60;

 

            IShape subtitle = slide1.AddTextBox(120.25, 283.68, 720, 130.32);

            textBody = subtitle.TextBody;

            textBody.VerticalAlignment = VerticalAlignmentType.Top;

            paragraph = textBody.AddParagraph();

            paragraph.HorizontalAlignment = HorizontalAlignmentType.Center;

            ITextPart textPart2 = paragraph.AddTextPart();

            textPart2.Text = "Steve Smith";

            textPart2.Font.FontName = "Calibri";

            textPart2.Font.FontSize = 24;

        }

 

        private static void CreateSlide2(IPresentation presentation)

        {

            //Create a slide with a blank layout.

            ISlide slide2 = presentation.Slides.Add(SlideLayoutType.Blank);

            //Add a text box for entering the title of the slide and set its vertical align as middle.

            IShape titleShape = slide2.AddTextBox(66.24, 28.8, 828, 104.4);

            titleShape.TextBody.VerticalAlignment = VerticalAlignmentType.Middle;

            //Add a paragraph into the title shape and set its vertical alignment as center.

            IParagraph paragraph = titleShape.TextBody.AddParagraph();

            paragraph.HorizontalAlignment = HorizontalAlignmentType.Center;

 

            //Create an instance of ITextPart and set the text and its formatting.

            ITextPart textPart1 = paragraph.AddTextPart();

            textPart1.Text = "Slide Title";

            textPart1.Font.FontName = "Calibri Light";

            textPart1.Font.FontSize = 44;

            //Add a new text box for the content of the slide and set its vertical alignment as top.

            IShape contentShape = slide2.AddTextBox(66.24, 144, 828, 342.72);

            contentShape.TextBody.VerticalAlignment = VerticalAlignmentType.Top;

 

            //Add a paragraph into the body of content shape.

            IParagraph para = contentShape.TextBody.AddParagraph();

 

            //Set the list format type as Numbered and the numbering style as Arabic followed by a period.

            para.ListFormat.Type = ListType.Numbered;

            para.ListFormat.NumberStyle = NumberedListStyle.ArabicPeriod;

 

            //Set the paragraph indentation as suitable for a list and add a space before the start of the paragraph.

            para.SpaceBefore = 10;

            para.LeftIndent = 40;

            para.FirstLineIndent = -40;

          

            //Add a text part and set the text and its formatting.

            ITextPart textPart2 = para.AddTextPart();

            textPart2.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

            textPart2.Font.FontName = "Calibri";

            textPart2.Font.FontSize = 28;

 

            para = contentShape.TextBody.AddParagraph();

            para.ListFormat.Type = ListType.Numbered;

            para.ListFormat.NumberStyle = NumberedListStyle.ArabicPeriod;

            para.SpaceBefore = 10;

            para.LeftIndent = 40;

            para.FirstLineIndent = -40;

 

            ITextPart textPart4 = para.AddTextPart();

            textPart4.Text = "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";

            textPart4.Font.FontName = "Calibri";

            textPart4.Font.FontSize = 28;

        }

    }

}

 



First Slide of the Presentation

Second Slide of the Presentation

Now that you know the basics of getting started, take a look at our online live demos for Essential Presentation. They serve as a good launching from which you can experiment with some of the features we’ve discussed.


Content Editor: Usha Clementine Henry | Content Contributor: Vijayakumar Srinivasan
Loading