Iterate through the collection and get a hyperlink text and URL.
The following example shows how to extract hyperlinks from the document page area:
// 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;}// Create the options which are used for hyperlink extraction
PageAreaOptionsoptions=newPageAreaOptions(newRectangle(newPoint(380,90),newSize(150,50)));// Extract hyperlinks from the document page area
Iterable<PageHyperlinkArea>hyperlinks=parser.getHyperlinks(options);// 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: