Read the complete article on how to add and remove hyperlinks in PowerPoint PPT/PPTX in C#: https://blog.aspose.com/2022/02/02/work-with-hyperlinks-in-powerpoint-ppt-in-csharp/
Last active
February 23, 2022 09:27
-
-
Save aspose-com-gists/98b601922a6701e34618c68d5bdc2536 to your computer and use it in GitHub Desktop.
Add or Remove Hyperlinks from PowerPoint PPT/PPTX in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("presentation.pptx")) | |
{ | |
// Insert audio | |
IAudio audio = presentation.Audios.AddAudio(File.ReadAllBytes("audio.mp3")); | |
IAudioFrame audioFrame = presentation.Slides[0].Shapes.AddAudioFrameEmbedded(10, 10, 100, 100, audio); | |
// Create hyperlink | |
audioFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
audioFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs"; | |
// Save presentation | |
presentation.Save("audio-hyperlink.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("presentation.pptx")) | |
{ | |
// Add image to presentation | |
IPPImage image = presentation.Images.AddImage(File.ReadAllBytes("image.png")); | |
// Create picture frame on slide 1 based on previously added image | |
IPictureFrame pictureFrame = presentation.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image); | |
// Create hyperlink | |
pictureFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
pictureFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs"; | |
// Save presentation | |
presentation.Save("image-hyperlink.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("presentation.pptx")) | |
{ | |
// Create an auto shape | |
IShape shape = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 600, 50); | |
// Create hyperlink | |
shape.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
shape.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs"; | |
// Save presentation | |
presentation.Save("shape-hyperlink.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("presentation.pptx")) | |
{ | |
// Create an auto shape for text | |
IAutoShape shape1 = presentation.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, false); | |
// Set text | |
shape1.AddTextFrame("Aspose: File Format APIs"); | |
// Set hyperlink | |
shape1.TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
shape1.TextFrame.Paragraphs[0].Portions[0].PortionFormat.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs"; | |
shape1.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 32; | |
// Save presentation | |
presentation.Save("text-hyperlink.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("presentation.pptx")) | |
{ | |
// Insert video | |
IVideo video = presentation.Videos.AddVideo(File.ReadAllBytes("wildlife.mp4")); | |
IVideoFrame videoFrame = presentation.Slides[0].Shapes.AddVideoFrame(10, 10, 100, 100, video); | |
// Create hyperlink | |
videoFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
videoFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs"; | |
// Save presentation | |
presentation.Save("video-hyperlink.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
using (Presentation presentation = new Presentation("text-hyperlink.pptx")) | |
{ | |
// Get reference of slide | |
ISlide slide = presentation.Slides[0]; | |
// Loop through shape | |
foreach (IShape shape in slide.Shapes) | |
{ | |
// Remove hyperlink if it is applied to shape | |
shape.HyperlinkManager.RemoveHyperlinkClick(); | |
// Proceed to remove hyperlink from the text | |
IAutoShape autoShape = shape as IAutoShape; | |
if (autoShape != null) | |
{ | |
foreach (IParagraph paragraph in autoShape.TextFrame.Paragraphs) | |
{ | |
foreach (IPortion portion in paragraph.Portions) | |
{ | |
portion.PortionFormat.HyperlinkManager.RemoveHyperlinkClick(); | |
} | |
} | |
} | |
} | |
// Save presentation | |
presentation.Save("remove-hyperlinks.pptx", SaveFormat.Pptx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment