Iterate through the collection and get a hyperlink text and URL.
The following example shows how to extract all hyperlinks from the whole document:
// Create an instance of Parser class
try(Parserparser=newParser(Constants.HyperlinksPdf)){// Check if the document supports hyperlink extraction
if(!parser.getFeatures().isHyperlinks()){System.out.println("Document isn't supports hyperlink extraction.");return;}// Extract hyperlinks from the document
Iterable<PageHyperlinkArea>hyperlinks=parser.getHyperlinks();// Iterate over hyperlinks
for(PageHyperlinkAreah:hyperlinks){// Print the hyperlink text
System.out.println(h.getText());// Print the hyperlink URL
System.out.println(h.getUrl());System.out.println();}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: