Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Wed Jul 24, 2019 12:09 pm

i have an existing template with placeholders for Text, image and video.

By looping the below code, i can get the placeholders for text and inserting data into respective placeholders.

foreach (IShape shapeType in presentation.Slides[0].Shapes)
{
if (shapeType is IAutoShape)
{
(shapeType as IAutoShape).TextFrame.Text = "First Sample Text";
}
}

But I was unable to retrieve the exact IShape for Image. i have tried with "SlidePicture" and "IEmbedImage" like below, but neither of them is working.

if (shapeType is SlidePicture || shapeType is IEmbedImage)
{
}


In the same manner the video file need to be detected and video should be added to the video placeholder.

Can you please help me out in inserting data into image and video placeholders ?

Naren510
 
Posts: 2
Joined: Wed Jul 24, 2019 11:52 am

Thu Jul 25, 2019 8:04 am

Hello,

Thanks for your inquiry.
Sorry to tell you that Spire.Presentation doesn't support adding image and video via placeholders at present. We will consider adding it as a new feature to our upgrade list. If it can be achieved in the future, we will let you know.
Here is a temporary workaround, that is obtaining the location and size of placeholders and then appending image and video at the location.
Please refer to the following code and test. If there is any question, please provide your templet file and expected output for our reference.
Code: Select all
static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            //Load the template with picture placeholder and media placeholder
            ppt.LoadFromFile("test.pptx");

            //To save the location information
            List<RectangleF> a = new List<RectangleF>();
            List<RectangleF> b = new List<RectangleF>();

            foreach (ISlide slide in ppt.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    //If it is a picture placeholder
                    if (shape.Placeholder.Type == PlaceholderType.Picture)
                    {
                        RectangleF rect = new RectangleF(shape.Left, shape.Top, shape.Width, shape.Height);
                        a.Add(rect);
                        shape.RemovePlaceholder();
                    }
                    //If it is a media placeholder
                    else if (shape.Placeholder.Type == PlaceholderType.Media)
                    {
                        RectangleF rect = new RectangleF(shape.Left, shape.Top, shape.Width, shape.Height);
                        b.Add(rect);
                        shape.RemovePlaceholder();
                    }
                }
                //Add piture
                foreach (RectangleF picture in a)
                {
                    string ImageFile = "img.png";
                    IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, picture);
                    image.Line.FillType = FillFormatType.None;
                }
                //Add video
                foreach (RectangleF media in b)
                {
                    string VideoFile = "video.mp4";
                    IVideo video = slide.Shapes.AppendVideoMedia(VideoFile , media);
                }
            }

            ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 369
Joined: Tue Jul 09, 2019 2:22 am

Mon Jul 29, 2019 7:18 am

Thank You Rachel, for your immediate response. I have checked with the Image and it worked like a Charm. I will follow the same for the Video and will check that.
Once again thank you very much for your immediate and an impressive support.

Naren510
 
Posts: 2
Joined: Wed Jul 24, 2019 11:52 am

Mon Jul 29, 2019 8:12 am

Hello,

Thanks for your feedback!
Glad to hear that my workaround fulfils your needs well. In the meanwhile, our Dev team is developing the new feature. Once it is achieved, we will let you know.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 369
Joined: Tue Jul 09, 2019 2:22 am

Mon Aug 12, 2019 10:34 am

Hello,

Glad to inform that we have just released Spire.Presentation Pack Hotfix Version:4.8.5 which supports adding image and video via placeholders. Please download it from the following links and refer to the following code.
Website: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget: https://www.nuget.org/packages/Spire.Presentation/
Code: Select all
foreach (ISlide slide in ppt.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    switch(shape.Placeholder.Type){
                        case PlaceholderType.Picture:
                            shape.InsertPicture("img.png");
                            break;
                        case PlaceholderType.Media:
                            shape.InsertPicture("video.mp4");
                            break;
                    }
                }
}


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 369
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Presentation