How do I delete hyperlinks in .ppt and .pptx slides without removing the text.
Hi David,
To remove the hyperlink and keep the text, you will need to set HLinkClick to null for the portion of the TextFrame having hyperlink. Please see the following sample code in this regard.
PresentationEx pres = new PresentationEx("c:\\data\\hLinkPPTX.pptx");
foreach (Aspose.Slides.Pptx.SlideEx slide in pres.Slides)
{
foreach (Aspose.Slides.Pptx.ShapeEx shape in slide.Shapes)
{
if (shape.ToString() == "Aspose.Slides.Pptx.AutoShapeEx" ||
shape.ToString() == "Aspose.Slides.Pptx.SlideEx")
{
Aspose.Slides.Pptx.AutoShapeEx shape1 = (Aspose.Slides.Pptx.AutoShapeEx)shape;
Aspose.Slides.Pptx.TextFrameEx txtframe = shape1.TextFrame;
foreach (Aspose.Slides.Pptx.ParagraphEx paragraph in txtframe.Paragraphs)
foreach (Aspose.Slides.Pptx.PortionEx portion in paragraph.Portions)
{
for (int i = 0; i < (paragraph.Portions.Count); i++)
{
//Set HLinkClick to null
paragraph.Portions[i].HLinkClick = null;
}
}
}
}
}
pres.Write("c:\\data\\hLinkPPTX_updated.pptx");
Please try the above code and in case you need any further assistance, please feel free to contact support.
Thanks & Regards,
This worked well for .pptx files but not all .ppt files. I attached a file that failed to convert to .pptx and failed when I tried to remove hyperlinks directly.
Hi David,
Thank you for sharing the template file.
I am looking into your issue and will get back to you soon.
Sorry for the inconvenience,
Hi David,
Thank you for being patient.
I checked your issue with Aspose.Slides for .NET v8.2.0 and I am unable to find any problem. I have used the following sample code for the PPT file you shared and it removes the links fine. Please try the below sample code for your PPT files and in case you still face any issue, please do let us know.
Presentation pres = new Presentation("c:\\data\\intro_to_cultural_anth.ppt");
foreach (Aspose.Slides.Slide slide in pres.Slides)
{
foreach (Aspose.Slides.Shape shape in slide.Shapes)
{
if (shape.IsTextHolder)
{
Aspose.Slides.TextHolder shape1 = (Aspose.Slides.TextHolder)shape.Placeholder;
LinkCollection links = shape1.Links;
links.Clear();
}
}
}
pres.Write("c:\\data\\intro_to_cultural_anth_update.ppt");
Thanks & Regards,
Thank you, your code worked well.
Cheers,
David