Friday, 24 August 2018 07:39

Add a Picture as a Custom Bullet Style in PowerPoint in C#

Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to add a picture as a custom bullet style in a PowerPoint file using Spire.Presentation.

Below is the screenshot of the example PowerPoint file:

Add a Picture as a Custom Bullet Style in PowerPoint in C#

Detail steps:

Step 1: Instantiate a Presentation object and load the PowerPoint file.

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"Input.pptx");

Step 2: Get the first shape on the first slide.

IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;

Step 3: Add a picture as the bullet style of the paragraphs in the shape.

foreach (TextParagraph paragraph in shape.TextFrame.Paragraphs)
{
    paragraph.BulletType = TextBulletType.Picture;
    Image bulletPicture = Image.FromFile(@"timg.jpg");
    paragraph.BulletPicture.EmbedImage = ppt.Images.Append(bulletPicture);
}

Step 4: Save the file.

ppt.SaveToFile(@"Output.pptx", FileFormat.Pptx2010);

Screenshot:

Add a Picture as a Custom Bullet Style in PowerPoint in C#

Full code:

using System.Drawing;
using Spire.Presentation;

namespace Add_Picture_as_Custom_Bullet_Style_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate a Presentation object
            Presentation ppt = new Presentation();
            //Load the PowerPoint file
            ppt.LoadFromFile(@"Input.pptx");

            //Get the first shape on the first slide
            IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;

            //Traverse through the paragraphs in the shape
            foreach (TextParagraph paragraph in shape.TextFrame.Paragraphs)
            {
                //Set the bullet style of paragraph as picture
                paragraph.BulletType = TextBulletType.Picture;
                //Load a picture
                Image bulletPicture = Image.FromFile(@"timg.jpg");
                //Add the picture as the bullet style of paragraph
                paragraph.BulletPicture.EmbedImage = ppt.Images.Append(bulletPicture);
            }

            //Save the file
            ppt.SaveToFile(@"Output.pptx", FileFormat.Pptx2010);
        }
    }
}

Additional Info

  • tutorial_title:
Last modified on Friday, 24 August 2018 07:42