Learn how to add or remove hyperlinks in PowerPoint PPT/PPTX in Java:
Last active
February 28, 2022 16:02
-
-
Save aspose-com-gists/f83f986aec97dbfcacb3bed11c1a3451 to your computer and use it in GitHub Desktop.
Add or Remove Hyperlinks in PowerPoint PPT in Java
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
// Create presentation | |
Presentation presentation = new Presentation(); | |
try { | |
// Add an audio element | |
IAudio audio = presentation.getAudios().addAudio(Files.readAllBytes(Paths.get("audio.mp3"))); | |
IAudioFrame audioFrame = presentation.getSlides().get_Item(0).getShapes().addAudioFrameEmbedded(10, 10, 100, 100, audio); | |
// Create hyperlink | |
audioFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
audioFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
// Save presentation | |
presentation.save("add-audio-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Create presentation | |
Presentation presentation = new Presentation(); | |
try { | |
// Add image to presentation | |
IPPImage image = presentation.getImages().addImage(Files.readAllBytes(Paths.get("image.png"))); | |
// Create picture frame on slide 1 based on previously added image | |
IPictureFrame pictureFrame = presentation.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image); | |
// Create hyperlink | |
pictureFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
pictureFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
// Save presentation | |
presentation.save("add-image-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Create presentation | |
Presentation presentation = new Presentation(); | |
try { | |
// Add an auto shape | |
IAutoShape shape1 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, | |
100, 600, 50, false); | |
// Set text | |
shape1.addTextFrame("Aspose: File Format APIs"); | |
// Get formatting of text portion | |
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0) | |
.getPortionFormat(); | |
// Add hyperlink | |
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
portionFormat.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
portionFormat.setFontHeight(32); | |
// Save presentation | |
presentation.save("add-shape-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Create presentation | |
Presentation presentation = new Presentation(); | |
try { | |
// Add an auto shape | |
IAutoShape shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, | |
100, 600, 50, false); | |
// Add hyperlink | |
shape.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
shape.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
// Save presentation | |
presentation.save("add-text-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Create presentation | |
Presentation presentation = new Presentation(); | |
try { | |
// Add video | |
IVideo video = presentation.getVideos().addVideo(Files.readAllBytes(Paths.get("video.avi"))); | |
IVideoFrame videoFrame = presentation.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 100, 100, video); | |
// Create hyperlink | |
videoFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
videoFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
// Save presentation | |
presentation.save("add-video-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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 | |
Presentation presentation = new Presentation("presentation.pptx"); | |
try { | |
// Remove hyperlink from text | |
ISlide slide = presentation.getSlides().get_Item(0); | |
for (IShape shape : slide.getShapes()) | |
{ | |
// Cast to IAutoShape | |
IAutoShape autoShape = (IAutoShape)shape; | |
if (autoShape != null) | |
{ | |
// Loop through paragraphs | |
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) | |
{ | |
// Loop through text portions | |
for (IPortion portion : paragraph.getPortions()) | |
{ | |
portion.getPortionFormat().getHyperlinkManager().removeHyperlinkClick(); | |
} | |
} | |
} | |
} | |
// Remove hyperlink from shapes | |
for (IShape shape : slide.getShapes()) | |
{ | |
shape.getHyperlinkManager().removeHyperlinkClick(); | |
} | |
// Save presentation | |
presentation.save("remove-hyperlink.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment