←Select platform

GetLinks Method

Summary

Links of this page.

Syntax

C#
VB
Java
C++
public DocumentLink[] GetLinks() 
Public Function GetLinks() As DocumentLink() 
public:  
   array<DocumentLink^>^ GetLinks() 
public DocumentLink[] getLinks() 

Return Value

An array containing the links for this page if available, or null.

Remarks

GetLinks is used to get the links found in this page. All document types support this method however, the page links (links that refer to another part of the document) are not read from the original document till DocumentStructure.IsParsed has been called and the value of DocumentStructure.ParsePageLinks is true.

SetLinks is used to replace the links of the page. IsLinksModified is used to as flag that indicates that the links of this page has been replaced by the user.

If this document uses the cache system (Document.HasCache is true), then the links are stored in the cache only when Document.SaveToCache is called.

When the value of DocumentText.AutoParseLinks is true and the page text is first obtained using GetText, then the document will attempt to also parse the text for links based on the regular expressions stored in LinkPatterns.

The LEADTOOLS Document Viewer uses this method to obtain the links of a page uses an interactive modes to modify the mouse cursor when the user to hover over a link as well as invoking the link target when the user clicks on a link.

Refer to Loading Using LEADTOOLS Documents Library for more information.

Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Documents; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
using Leadtools.Barcode; 
 
public static void DocumentPageGetLinksExample() 
{ 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Leadtools.pdf"), options)) 
   { 
      // Show the links before parsing the URL in the text 
      Console.WriteLine("Before get text"); 
      Console.WriteLine("---------"); 
      var page = document.Pages[0]; 
      ShowLinks(page); 
 
      // Make sure we will parse the hyper links 
      document.Text.AutoParseLinks = true; 
 
      // Show the regular expressions 
      Console.WriteLine("Parsing links from the text using these regular expressions:"); 
      foreach (var regex in DocumentText.LinkPatterns) 
      { 
         Console.WriteLine(regex.ToString()); 
      } 
 
      // Now, get the text to parse the links from it 
      page.GetText(); 
 
      // Show the links before parsing the URL in the text. It should now show the original plus any parsed URLs from the text 
      Console.WriteLine("After get text"); 
      Console.WriteLine("---------"); 
      ShowLinks(page); 
   } 
} 
 
private static void ShowLinks(Leadtools.Documents.DocumentPage page) 
{ 
   var links = page.GetLinks(); 
   if (links != null) 
   { 
      int index = 0; 
      Console.WriteLine("Page " + page.PageNumber); 
      foreach (var link in links) 
      { 
         Console.WriteLine(index++); 
         Console.WriteLine("  Bounds:" + link.Bounds); 
         Console.WriteLine("  LinkType:" + link.LinkType); 
         if (link.LinkType == DocumentLinkType.Value) 
         { 
            Console.WriteLine("  Value:" + link.Value); 
         } 
         else 
         { 
            Console.WriteLine("  Target.PageFitType:" + link.Target.PageFitType); 
            Console.WriteLine("  Target.PageNumber:" + link.Target.PageNumber); 
            Console.WriteLine("  Target.Position:" + link.Target.Position); 
            Console.WriteLine("  Target.ZoomPercent:" + link.Target.ZoomPercent); 
         } 
         Console.WriteLine(); 
      } 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Svg 
Imports Leadtools.Documents 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Barcode 
Imports Leadtools.Forms.Ocr 
Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
'Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
 
Public Shared Sub DocumentPageGetLinksExample() 
   Dim options As New LoadDocumentOptions() 
   Using document As Leadtools.Documents.Document = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Leadtools.pdf"), options) 
      ' Show the links before parsing the URL in the text 
      Console.WriteLine("Before get text") 
      Console.WriteLine("---------") 
      Dim page As Leadtools.Documents.DocumentPage = document.Pages(0) 
      ShowLinks(page) 
 
      ' Make sure we will parse the hyper links 
      document.Text.AutoParseLinks = True 
 
      ' Show the regular expressions 
      Console.WriteLine("Parsing links from the text using these regular expressions:") 
      For Each regex As Regex In DocumentText.LinkPatterns 
         Console.WriteLine(regex.ToString()) 
      Next 
 
      ' Now, get the text to parse the links from it 
      page.GetText() 
 
      ' Show the links before parsing the URL in the text. It should now show the original plus any parsed URLs from the text 
      Console.WriteLine("After get text") 
      Console.WriteLine("---------") 
      ShowLinks(page) 
   End Using 
End Sub 
 
Private Shared Sub ShowLinks(page As Leadtools.Documents.DocumentPage) 
   Dim links() As DocumentLink = page.GetLinks() 
   If Not IsNothing(links) Then 
      Dim index As Integer = 0 
      Console.WriteLine("Page " + page.PageNumber.ToString()) 
      For Each link As DocumentLink In links 
         Console.WriteLine(index) 
         index = index + 1 
         Console.WriteLine("  Bounds:" + link.Bounds.ToString()) 
         Console.WriteLine("  LinkType:" + link.LinkType.ToString()) 
         If link.LinkType = DocumentLinkType.Value Then 
            Console.WriteLine("  Value:" + link.Value) 
         Else 
            Console.WriteLine("  Target.PageFitType:" + link.Target.PageFitType.ToString()) 
            Console.WriteLine("  Target.PageNumber:" + link.Target.PageNumber.ToString()) 
            Console.WriteLine("  Target.Position:" + link.Target.Position.ToString()) 
            Console.WriteLine("  Target.ZoomPercent:" + link.Target.ZoomPercent.ToString()) 
         End If 
         Console.WriteLine() 
      Next 
   End If 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly