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