Extract hyperlinks from document

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-parser -- dnx GroupDocs.Parser.Mcp --yes
Folders, licensing and more →

GroupDocs.Parser provides the functionality to extract hyperlinks from documents by the getHyperlinks() method:

parser.getHyperlinks() // returns Iterable<PageHyperlinkArea>

This method returns a Java Iterable collection of PageHyperlinkArea objects:

MemberDescription
getPage()The page that contains the hyperlink.
getRectangle()The rectangular area on the page that contains the hyperlink.
getText()The hyperlink text.
getUrl()The hyperlink URL.

Here are the steps to extract all hyperlinks from the whole document:

  • Instantiate the Parser object for the initial document;
  • Check if the document supports hyperlink extraction;
  • Call the getHyperlinks() method and obtain the collection of PageHyperlinkArea objects;
  • Iterate through the collection and get a hyperlink text and URL.

The following example shows how to extract all hyperlinks from the whole document:

const groupdocs = require('@groupdocs/groupdocs.parser');

// Create an instance of Parser class
const parser = new groupdocs.Parser('Hyperlinks.pdf');
try {
  // Check if the document supports hyperlink extraction
  if (!parser.getFeatures().isHyperlinks()) {
    console.log("Document doesn't support hyperlink extraction.");
  } else {
    // Extract hyperlinks from the document
    const it = parser.getHyperlinks().iterator();
    // Iterate over hyperlinks
    while (it.hasNext()) {
      const h = it.next();
      // Print the hyperlink text
      console.log(h.getText());
      // Print the hyperlink URL
      console.log(h.getUrl());
      console.log();
    }
  }
} finally {
  parser.close();
}
process.exit(0);

The output for Hyperlinks.pdf:

Lorem ipsum
http://link1/

pharetra nonummy
http://link11/

Donec ut est
http://link2/

Maecenas odio
http://link21/

More resources

Free online document parser App

Along with the full-featured library we provide simple but powerful free Apps.

You are welcome to extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our Free Online Document Parser App.