Hyperlinks in PowerPoint are clickable objects that enable you to jump to another slide in the same/different PowerPoint document or to a specific website. They are a great way to add additional resources to your slides, and they can also make the document more interactive. In addition to adding hyperlinks to PowerPoint documents, Spire.Presentation for Java also supports modifying and removing the existing hyperlinks. This article is going to introduce how to achieve the above two functions.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.presentation</artifactId> <version>9.10.2</version> </dependency> </dependencies>
Modify Hyperlinks in PowerPoint
With Spire.Presentation for Java, you are allowed to set a new hyperlink address and display text for the existing hyperlink. The following are the detailed steps to modify a hyperlink in PowerPoint.
- Create a Presentation object and load a PowerPoint document using Presentation.loadFromFile() method.
- Get a specified slide using Presentation.getSlides().get() method.
- Get the shapes of the specified slide using getShapes() method under ISlide interface, and then get the specified shape that contains the hyperlink using ShapeList.get() method.
- Get the text range of the existing hyperlink using IAutoShape.getTextFrame().getTextRange() method, and then set a new hyperlink display text for the text range using PortionEx.setText() method.
- Get the existing clickable hyperlink of the text range using TextCharacterProperties.getClickAction() method, and then set a new hyperlink address using ClickHyperlink.setAddress() method.
- Save the document to file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*; public class modifyHyperlink { public static void main(String[] args) throws Exception { //Create a Presentation object and load a PowerPoint document Presentation presentation = new Presentation(); presentation.loadFromFile("test.pptx"); //Get the shape that contains the hyperlink IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0); //Edit the hyperlink text and address shape.getTextFrame().getTextRange().setText("Spire.Presentation for Java"); shape.getTextFrame().getTextRange().getClickAction().setAddress("https://www.e-iceblue.com/Introduce/presentation-for-java.html"); //Save to file. presentation.saveToFile("ModifyHyperlink.pptx", FileFormat.PPTX_2013); } }
Remove Hyperlinks in PowerPoint
When a hyperlink needs to be removed for some reason, Spire.Persentation for Java provides the TextCharacterProperties.setClickAction() method. And by setting its value to null, you could remove the hyperlink easily in PowerPoint. The detailed steps are as follows:
- Create a Presentation object and load a PowerPoint document using Presentation.loadFromFile() method.
- Get a specified slides using Presentation.getSlides().get() method.
- Get the shapes of the specified slide using getShapes() method under ISlide interface, and then get the specified shape that contains the hyperlink using ShapeList.get() method.
- Get the text range of the existing hyperlink using IAutoShape.getTextFrame().getTextRange() method, and then remove the hyperlink by setting the value of the TextCharacterProperties.setClickAction() method to null.
- Save the document to file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.*; public class removeHyperlink { public static void main(String[] args) throws Exception { //Create a Presentation object and load a PowerPoint document Presentation presentation = new Presentation(); presentation.loadFromFile("test.pptx"); //Get the shape that contains the hyperlink. IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0); //Set the click action to null to remove the hyperlink. shape.getTextFrame().getTextRange().setClickAction(null); //Save to file. presentation.saveToFile("RemoveHyperlink.pptx", FileFormat.PPTX_2013); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.