Leadtools.Documents名前空間 > DocumentPageクラス :GetLinksメソッド |
public DocumentLink[] GetLinks()
'Declaration
Public Function GetLinks() As DocumentLink()
'Usage
Dim instance As DocumentPage Dim value() As DocumentLink value = instance.GetLinks()
public DocumentLink[] getLinks()
public: array<DocumentLink>^ GetLinks();
GetLinksは、このページで見つけられるリンクを取得するのに用いられます。すべてのドキュメント形式はこのメソッドをサポートしますが、DocumentStructure.IsParsedが呼び出され、DocumentStructure.ParsePageLinksの値がtrueにならないかぎり、ページリンク(文書内の別の部分を参照するリンク)がオリジナル文書から読み込まれることはありません。
SetLinksは、ページのリンクを置換するのに用いられます。IsLinksModifiedはフラグとして使用され、このページのリンクがユーザーによって置換されたことを示します。
このドキュメントがキャッシュシステム(Document.HasCacheはtrueです)を使うならば、Document.SaveToCacheが呼び出される時だけ、リンクはキャッシュで保存されます。
DocumentText.AutoParseLinksの値がtrueであり、ページのテキストがGetTextを使って最初に取得されるとき、DocumentText.LinkPatterns。に格納される正規表現に基づいてリンクのテキストも解析しようとします。詳細については、「AutoParseLinks」を参照してください。
LEADTOOLSドキュメントビューワは、このメソッドを使用してページのリンクを取得します。対話モードを使用して、ユーザーがリンクの上にマウスを重ねるときのマウスカーソルを変更します。ユーザーがリンクをクリックするときにリンクターゲットを呼び出します。
詳細については、「LEADTOOLSドキュメントライブラリを使用したロード」を参照してください。
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 <TestMethod()> _ Public Sub DocumentPageGetLinksExample() Dim options As New LoadDocumentOptions() options.UseCache = False 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 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
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms.DocumentWriters; using Leadtools.Svg; using Leadtools.Documents; using Leadtools.Caching; using Leadtools.Annotations.Core; using Leadtools.Forms.Ocr; using Leadtools.Barcode; [TestMethod] public void DocumentPageGetLinksExample() { var options = new LoadDocumentOptions(); options.UseCache = false; 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 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(); } } }