Iterate through the collection and get a hyperlink text and URL.
The following example shows how to extract hyperlinks from the document page:
// 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;}// Get the document info
IDocumentInfodocumentInfo=parser.getDocumentInfo();// Check if the document has pages
if(documentInfo.getPageCount()==0){System.out.println("Document hasn't pages.");return;}// Iterate over pages
for(intpageIndex=0;pageIndex<documentInfo.getPageCount();pageIndex++){// Print a page number
System.out.println(String.format("Page %d/%d",pageIndex+1,documentInfo.getPageCount()));// Extract hyperlinks from the document page
Iterable<PageHyperlinkArea>hyperlinks=parser.getHyperlinks(pageIndex);// 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: