For each slide, how would I get the text of a hyperlink? I can get the ExternalUrl
, but don’t see the text anywhere.
@dmerkle1,
Thank you for posting the question.
Please read the following article: Manage Hyperlinks|Aspose.Slides Documentation. If it does not help you, could you kindly share a simple code example that shows the problem?
Hi andrey, thanks for the reply. I checked out that documentation and it did not help. So when you link something in a powerpoint, there is the text, and the link. I can get the link, but not the text.
image.png (23.0 KB)
So in the picture above, using Aspose.Slides, I can get the link of https://www.google.com, but I can not get the text of Google.
Usually, this is done the other way around, you first get the text and extract a hyperlink from it. Could you please show with a code example how you get the link?
IList<Aspose.Slides.IHyperlinkContainer> links =
slide.HyperlinkQueries.GetAnyHyperlinks();
foreach(var link in links)
{
var url = link.HyperlinkClick.ExternalUrl;
}
Could you share an example of “the other way around”?
Thanks
@dmerkle1,
Thank you for the additional information. I am working on your questions and will get back to you soon.
@dmerkle1,
The method GetAnyHyperlinks
is intended to retrieve only hyperlinks from a presentation, and it does not return text. To extract hyperlinks with text, you can enumerate paragraphs and text portions and find them like this:
using var presentation = new Presentation("sample.pptx");
// Let's say the first shape on the first slide is a text box.
ISlide firstSlide = presentation.Slides[0];
IAutoShape autoShape = firstSlide.Shapes[0] as IAutoShape;
foreach (var paragraph in autoShape.TextFrame.Paragraphs)
{
foreach (var portion in paragraph.Portions)
{
if (portion.PortionFormat.HyperlinkClick != null)
{
Console.WriteLine("Text portion: " + portion.Text);
var externalUrl = portion.PortionFormat.HyperlinkClick.ExternalUrl;
Console.WriteLine("External URL: " + externalUrl);
}
}
}
Awesome, thanks.