GetHyperlinks

Extracts hyperlinks from the document.

public IEnumerable<PageHyperlinkArea> GetHyperlinks()

Return Value

A collection of PageHyperlinkArea objects; null if hyperlinks extraction isn’t supported.

Examples

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

// 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;
    }
    // Extract hyperlinks from the document
    IEnumerable<PageHyperlinkArea> hyperlinks = parser.GetHyperlinks();
    // 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();
    }
}

See Also


Extracts hyperlinks from the document page.

public IEnumerable<PageHyperlinkArea> GetHyperlinks(int pageIndex)
Parameter Type Description
pageIndex Int32 The zero-based page index.

Return Value

A collection of PageHyperlinkArea objects; null if hyperlinks extraction isn’t supported.

Examples

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();
        }
    }
}

See Also


Extracts hyperlinks from the document using customization options (to set the rectangular area that contains hyperlinks).

public IEnumerable<PageHyperlinkArea> GetHyperlinks(PageAreaOptions options)
Parameter Type Description
options PageAreaOptions The options for hyperlinks extraction.

Return Value

A collection of PageHyperlinkArea objects; null if hyperlinks extraction isn’t supported.

Examples

The following example shows how to extract hyperlinks from the document page area:

// 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;
    }
    // Create the options which are used for hyperlink extraction
    PageAreaOptions options = new PageAreaOptions(new Rectangle(new Point(380, 90), new Size(150, 50)));
    // Extract hyperlinks from the document page area
    IEnumerable<PageHyperlinkArea> hyperlinks = parser.GetHyperlinks(options);
    // 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();
    }
}

See Also


Extracts hyperlinks from the document page using customization options (to set the rectangular area that contains hyperlinks).

public IEnumerable<PageHyperlinkArea> GetHyperlinks(int pageIndex, PageAreaOptions options)
Parameter Type Description
pageIndex Int32 The zero-based page index.
options PageAreaOptions The options for hyperlinks extraction.

Return Value

A collection of PageHyperlinkArea objects; null if hyperlinks extraction isn’t supported.

Examples

The following example shows how to extract hyperlinks from the document page area using customization options:

// 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;
    }
    
    // Create the options which are used for hyperlink extraction
    PageAreaOptions options = new PageAreaOptions(new Rectangle(new Point(380, 90), new Size(150, 50)));
    // 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 area
        IEnumerable<PageHyperlinkArea> hyperlinks = parser.GetHyperlinks(pageIndex, options);
        // 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();
        }
}

See Also