We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Read Hyperlink Name from ppt slide

Hi Team,

I’m trying to read hyperlinks from a ppt file.
I have used: slide.getHyperlinkQueries().getAnyHyperlinks().get_Item(j).getHyperlinkClick().getExternalUrl();
This gives me the url to which hyperlink points.
How can I read the name (display text) of the hyperlink?

Regards,
Vineet

@vineet992,

I have observed the requirements shared by you and suggest you to please try using following sample code on your end to get the Hyperlink as well as display text for Hyperlink.

public static void ExtractHTMlLink()
{
Presentation pptxPresentation = new Presentation("D:\Aspose Data\HyperlinkTest.pptx");

List HypLinks = new List();

//Get an Array of TextFrameEx objects from the first slide
ITextFrame[] textFramesSlideOne = SlideUtil.GetAllTextBoxes(pptxPresentation.Slides[0]);

//Loop through the Array of TextFrames
for (int i = 0; i < textFramesSlideOne.Length; i++)

//Loop through paragraphs in current TextFrame
foreach (Paragraph para in textFramesSlideOne[i].Paragraphs)

//Loop through portions in the current Paragraph
foreach (Portion port in para.Portions)
{
if (port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick != null)
{
HypLinks.Add(port.PortionFormat.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
Console.Writelins("Hyperlink Text :"+port.Text);
}
}

///////////

//Loop through the Array of TextFrames
for (int j = 0; j < pptxPresentation.Slides.Count; j++)

//Loop through paragraphs in current TextFrame
foreach (IShape shape in pptxPresentation.Slides[j].Shapes)

{
if (shape.AsIHyperlinkContainer.HyperlinkClick != null)
{
HypLinks.Add(shape.AsIHyperlinkContainer.HyperlinkClick.ExternalUrl);
}
}

} 

I hope the shared information will be helpful.

@mudassir.fayyaz

Thanks. I’m using Aspose Slides for java. Can you pls help me with the java version?

Regards,
Vineet.

@vineet992,

I have modified code sample w.r.t Java. Please try using following sample code on your end.

public static void ExtractHTMlLink()
{
    Presentation pptxPresentation = new Presentation("D:\\Aspose Data\\HyperlinkTest.pptx");

    List<String> HypLinks = new ArrayList<String>();

    //Get an Array of TextFrameEx objects from the first slide
    ITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(pptxPresentation.getSlides().get_Item(0));

    //Loop through the Array of TextFrames
    for (int i = 0; i < textFramesSlideOne.length; i++)
    {
        int cnt=textFramesSlideOne[i].getParagraphs().getCount();

        for (int parIndex = 0; parIndex < cnt; parIndex++)
        {  
            IParagraph para = textFramesSlideOne[i].getParagraphs().get_Item(parIndex);

           //Loop through portions in the current Paragraph
           for (int portIndex=0;portIndex<para.getPortions().getCount();portIndex++)
           {
               IPortion port = para.getPortions().get_Item(portIndex);
               if (port.getPortionFormat().getHyperlinkClick() != null)
               {
                   HypLinks.add(port.getPortionFormat().getHyperlinkClick().getExternalUrl());
                    System.out.println("Hyperlink Text :"+port.getText());
               }
            }
        }
    }

    //Loop through the Array of TextFrames
    for (int j = 0; j < pptxPresentation.getSlides().size(); j++)

    //Loop through paragraphs in current TextFrame
    //foreach (IShape shape in pptxPresentation.Slides[j].Shapes)
    for (int ishapeCount=0;ishapeCount<pptxPresentation.getSlides().get_Item(j).getShapes().size();ishapeCount++)
    {
        IShape shape = pptxPresentation.getSlides().get_Item(j).getShapes().get_Item(ishapeCount);

        if (shape.getHyperlinkClick() != null)
        {
            HypLinks.add(shape.getHyperlinkClick().getExternalUrl());
        }

    }

}