Powerpoint has a feature of inserting media picture or video as a link.
But I don’t find such a feature in aspose slides.
I see that you have sample code for inserting image into PictureFrame and Video into VideoFrame, but this embeds the picture or video into the PPTX file and makes its size very large.
I want to insert a image or a video but not embed it into the pptx file but only insert it as a link.
Also I want to do this to a existing placeholder on a slide.
The placeholder maybe of type picture, media or object.
Is there any sample code that I missed?
Language would be C#.
@tomasmuller,
Thank you for posting the query. We will reply to you as soon as possible.
@tomasmuller,
You can set any link into placeholders just like other shapes as shown below:
placeholderShape.HyperlinkClick = new Hyperlink("https://www.mysite.com/test.jpg");
placeholderShape.HyperlinkClick.Tooltip = "This is the link to an image.";
Documents: Manage Hyperlinks
API Reference: IShape Interface | IHyperlink Interface
If you mean otherwise, please share a simple presentation with an example.
Like I said I don’t want a hyperlink. I want to insert an image or video as a link (without embedding) it in the Powerpoint file.
I want to do this to a existing placeholder on a powerpoint slide.
Picture is attached of how to do it by gui in Powerpoint, I want to achieve the same thing with C# code .
Link to picture for placeholder.png (80.5 KB)
@tomasmuller,
Thank you for the additional information.
Unfortunately, I was unable to find a way to create such a link by using Aspose.Slides. I logged the issue with ID SLIDESNET-42915 in our tracking system. Our development team will investigate this case. We will reply to you as soon as possible.
@tomasmuller,
Our development team has investigated the issue. After something is inserted into a placeholder in PowerPoint, it is replaced with a shape of the appropriate type. You can perform the same way as shown below:
using (var presentation = new Presentation("input.pptx"))
{
var shapesToRemove = new List<IShape>();
int shapesCount = presentation.Slides[0].Shapes.Count;
for (var i = 0; i < shapesCount; i++)
{
var autoShape = presentation.Slides[0].Shapes[i];
if (autoShape.Placeholder == null)
{
continue;
}
switch (autoShape.Placeholder.Type)
{
case PlaceholderType.Picture:
var pictureFrame = presentation.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle,
autoShape.X, autoShape.Y, autoShape.Width, autoShape.Height, null);
pictureFrame.PictureFormat.Picture.LinkPathLong =
"https://upload.wikimedia.org/wikipedia/commons/3/3a/I.M_at_Old_School_Public_Broadcasting_in_October_2016_02.jpg";
shapesToRemove.Add(autoShape);
break;
case PlaceholderType.Media:
var videoFrame = presentation.Slides[0].Shapes.AddVideoFrame(
autoShape.X, autoShape.Y, autoShape.Width, autoShape.Height, "");
videoFrame.PictureFormat.Picture.LinkPathLong =
"https://upload.wikimedia.org/wikipedia/commons/3/3a/I.M_at_Old_School_Public_Broadcasting_in_October_2016_02.jpg";
videoFrame.LinkPathLong = "https://youtu.be/t_1LYZ102RA";
shapesToRemove.Add(autoShape);
break;
}
}
foreach (var shape in shapesToRemove)
{
presentation.Slides[0].Shapes.Remove(shape);
}
presentation.Save("output.pptx", SaveFormat.Pptx);
}
Documents: Picture Frame, Video Frame
API Reference: PictureFrame Class | VideoFrame Class