Extract hyperlinks from document page

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 runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

GroupDocs.Parser provides the functionality to extract hyperlinks from document page by the GetHyperlinks(Int32) method:

IEnumerable<PageHyperlinkArea> GetHyperlinks(int pageIndex);

This method returns a collection of PageHyperlinkArea object:

MemberDescription
PageThe page that contains the text area.
RectangleThe rectangular area on the page that contains the text area.
TextThe hyperlink text.
UrlThe hyperlink URL.

Here are the steps to extract hyperlinks from the document page:

  • Instantiate Parser object for the initial document;
  • Check if the document supports hyperlink extraction;
  • Call GetHyperlinks(Int32) method with the page index and obtain collection of PageHyperlinkArea objects;
  • 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
using (Parser parser = new Parser(filePath))
{
    // Check if the document supports hyperlink extraction
    if (!parser.Features.Hyperlinks)
    {
        Console.WriteLine("Document isn't supports hyperlink extraction.");
        return;
    }
    // Get the document info
    IDocumentInfo documentInfo = parser.GetDocumentInfo();
    // Check if the document has pages
    if (documentInfo.PageCount == 0)
    {
        Console.WriteLine("Document hasn't pages.");
        return;
    }
    // Iterate over pages
    for (int pageIndex = 0; pageIndex < documentInfo.PageCount; pageIndex++)
    {
        // Print a page number 
        Console.WriteLine(string.Format("Page {0}/{1}", pageIndex + 1, documentInfo.PageCount));
        // Extract hyperlinks from the document page
        IEnumerable<PageHyperlinkArea> hyperlinks = parser.GetHyperlinks(pageIndex);
        // Iterate over hyperlinks
        foreach (PageHyperlinkArea h in hyperlinks)
        {
            // Print the hyperlink text
            Console.WriteLine(h.Text);
            // Print the hyperlink URL
            Console.WriteLine(h.Url);
            Console.WriteLine();
        }
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online image extractor App

Along with full featured .NET library we provide simple, but powerfull free APPs.

You are welcome to extract images from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online GroupDocs Parser App.