Find Hyperlinks

I am trying to analyse all hyperlinks in a slide or presentation. I am not able to locate all hyperlinks, despite placeholders or text frames showing a link count greater than 0. I need to be able find out if any internal/external links in any content on the slide and handle all links with my application. I have also noticed that there is not a consistent way of reading all text on a slide. Text frames contained in placeholders do not have text but shapes outside of a placeholder have text in text frames. Could you please clarify the best approach to read all text...and all hyperlinks.

Thanks.

You shouldn’t read textFrame inside TextHolder. It’s always empty (sometimes it can have text but it’s very rare and wrong thing) and exists just for reference.

The best way to read text is:

for (int i = 1; i <= pres.Slides.LastSlidePosition; i++)
{
Slide slide = pres.GetSlideByPosition( i );
for (int j = 0; j < slide.Shapes.Count; j++)
{
Shape shape = slide.Shapes[ j ];
if (!shape.IsTextHolder && shape.TextFrame != null)
{
text = text + “\n” + shape.TextFrame.Text;
}
}
for (int j = 0; j < slide.Placeholders.Count; j++)
{
Placeholder holder = slide.Placeholders[j];
if (holder is TextHolder)
{
TextHolder th = (TextHolder)holder;
text = text + “\n” + th.Text;

}
}
}

There are 2 different hyperlink types:
1. hyperlinks in the text. Can be accessed as TextFrame.Links or TextHolder.Links
2. hyperlink for a shape. Accessed as Shape.Link

Could you show any examples why you can’t get a link?

Ok so that is working fairly well as far as reading text, however the links are still an issue. Attached is the PPT i am using for testing and below is the test code. There are two links in the PPT. One for internal link and one for an external link. Running the code the first link(internal) appears to show expected information. The second link(external) does not show expected information. I am using a winforms app and simply displaying all the text in a text box.

This may answer your question. Since there was some confusion from the original post about where text was located I was not seeing what I thought should be seen concerning links. So I was trying to access the links property from other objects such as Paragraph and Portions to see if they had the actual link information.

There also seems to be a diferent layer of information depending on how a shape is cast. For example if the shape is cast to a VideoFrame it shows the file link information, but the link does not show in the code below.

private string ProcessLink(Link link, int shapeid, int linkid) {

string text = "";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].Begin: " + link.Begin + "\r\n";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].End: " + link.End + "\r\n";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].ExternalHyperlink: " + link.ExternalHyperlink + "\r\n";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].InternalHyperlink: " + link.InternalHyperlink + "\r\n";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].JumpType: " + link.JumpType + "\r\n";

text += "Shape.TextFrame[" + shapeid + "].Links[" + linkid + "].ActionType: " + link.ActionType + "\r\n";

return text;

}

public string GetSlideShapes(int id)

{

string text = "";

Slide slide = presentation.Slides[id];

for (int j = 0; j < slide.Shapes.Count; j++) {

Shape shape = slide.Shapes[j];

if (!shape.IsTextHolder && shape.TextFrame != null) {

text += "Shape.TextFrame[" + j + "]: " + shape.TextFrame.Text + "\r\n";

text += "Shape.TextFrame[" + j + "]: " + shape.TextFrame.Links.Count + "\r\n";

for (int x = 0; x < shape.TextFrame.Links.Count; x++) {

Link link = shape.TextFrame.Links[x];

text += ProcessLink(link, j, x);

}

}

}

for (int j = 0; j < slide.Placeholders.Count; j++) {

Placeholder placeholder = slide.Placeholders[j];

if (placeholder is TextHolder) {

TextHolder th = (TextHolder)placeholder;

text += "Place.TextHolder[" + j + "]: " + th.Text + "\r\n";

text += "Place.TextHolder[" + j + "]: " + th.Links.Count + "\r\n";

for (int x = 0; x < th.Links.Count; x++) {

Link link = th.Links[x];

text += ProcessLink(link, j, x);

}

}

}

return text;

}

Thank you for the report and presentation. Third slide of your ppt file contains external hyperlink
with unknown link type (we didn’t see such types before). I have added support for this new type.
Please check attached new version of Aspose.Slides. If everything will work right we will
include it to the next hot fix.

Excellent it seems to be working, The link was added using Office
2003. Unfortunately, while testing other docs I came across this
error. Just so you know because it may not be related to the
current production version. This error occured in a web application and
not the windows app on the same document. While debugging the
error occurs when I call the copy slide function. Thanks
again. Anyway here is the stack trace



System.Exception was unhandled by user code

Message=“Read wrong number of bytes from Escher record.”

Source=“Aspose.Slides”

StackTrace:

at ߞ.߼.߿(ࠇ ߾, BinaryReader ࠁ)

at ߞ.ख.߿(Object ࠀ, BinaryReader ࠁ, Int32 ࠏ)

at ߞ.ऎ.DoRead(BinaryReader reader)

at ߞ.߼.߿(ࠇ ߾, BinaryReader ࠁ)

at ठ.੽.FillFields(Byte[] data, Int32 size)

at ठ.थ…ctor(Object root, Int16 id, Int32 size, Byte[] data)

at ठ.ट.उ(Object ࠀ, Int16 ࠍ, Int16 ण, Int32 ӫ, Byte[] ԅ, ल त)

at ठ.ट.ड(Object ࠀ, Stream ढ)

at ठ.୰.FillFields(Byte[] data, Int32 size)

at ठ.थ…ctor(Object root, Int16 id, Int32 size, Byte[] data)

at ठ.୰…ctor(Object root, Int16 id, Int32 size, Byte[] data)

at Aspose.Slides.Slide.਄(Presentation ਅ)

at Aspose.Slides.Presentation.ਾ(Slide ਿ, Presentation ਅ, SortedList ਀, Slide ੀ)

at
Aspose.Slides.Presentation.CloneSlide(Slide srcSlide, Int32 position,
Presentation pres, SortedList idList)

at
…Data.BLL.PowerPointBLLogic.SaveSlide(Slide& slide, Int32 id) in
c:\Inetpub\wwwroot…\App_Code\Providers\PowerPointBLLogic.cs:line 325

at …Data.BLL.PowerPointBLLogic.Import() in …

It would be great if you can provide presentation with such error.
If I’m not mistaken error happened when you simply called CloneSlide method?