Link annotations are used to create any part of the document as hyperlinks. In other words, it allows us to associate external data with the specified area of the document. We can add these link annotations to documents within Java applications. In this article, you will learn how to create hyperlinks in PDF files using Java.
The following topics are covered below:
Java API to Create Hyperlinks in PDF
GroupDocs.Annotation provides the Java API that allows manipulation and automation of various annotations in documents within your Java-based applications. We will use this API to create hyperlink annotation in the PDF file.
Download or Configure
Download the JAR file from the downloads section, or just get the latest repository and dependency configurations for the pox.xml of your maven-based Java applications.
<repository> <id>GroupDocsJavaAPI</id> <name>GroupDocs Java API</name> <url>http://repository.groupdocs.com/repo/</url> </repository> <dependency> <groupId>com.groupdocs</groupId> <artifactId>groupdocs-annotation</artifactId> <version>21.7</version> </dependency>
Create Hyperlinks in PDF using Java
The following are the steps to create hyperlinks anywhere in PDF using Java.
- Load the PDF document using Annotator class.
- Define list of Points that represent the area of Hyperlink.
- Create the LinkAnnotation object.
- Define the hyperlink properties like url, page number, points, etc.
- Add the defined hyperlink to the loaded PDF document using add method.
- Save the annotated PDF using save method.
The following Java code shows how to convert any part of the PDF file into a hyperlink programmatically.
The following is the output of the above code.
Get a Free API License
You can get a free temporary license in order to use the API without the evaluation limitations.
To sum up, we have discussed how to programmatically add link annotations to create hyperlinks in PDF files using Java. By using link annotations, you can modify any part of the document into hyperlinks. Many different types of annotations are available through the API. These annotations can be added in a similar way using the same API. To learn more about the API, visit the documentation. For queries, contact us via the forum.