←Select platform

LoadFromUriAsync Method

Summary

Loads a document asynchronously from existing data stored in a remote URL.

Syntax
C#
VB
C++
public static void LoadFromUriAsync( 
   Uri uri, 
   LoadDocumentAsyncOptions options 
) 
Public Shared Sub LoadFromUriAsync( 
   ByVal uri As System.Uri, 
   ByVal options As LoadDocumentAsyncOptions 
) 
public:  
   static void LoadFromUriAsync( 
      System::Uri^ uri, 
      LoadDocumentAsyncOptions^ options 
   ) 

Parameters

uri

Path to the URL containing the original document data. This value cannot be null.

options

Options to use when loading the document. This value cannot be null.

Remarks

This method might use the cache and will throw an exception if neither LoadDocumentOptions.Cache nor Cache was setup with a valid cache object if certain options are used.

LoadFromUriAsync will start loading the document in a separate thread and return control to the user immediately. The LoadDocumentAsyncOptions class contains the Progress and Completed events that can be used to track the progress of the load and be notified when the operation is completed.

Note that uri can point to a document stored in HTTP, HTTPS, FTP, or Disk file (using the file protocol).

LoadFromFile, LoadFromUri, LoadFromUriAsync and LoadFromStream creates a LEADDocument class from any supported image or document file format stored in a disk file, remote URL or stream. The returned object can then be used to retrieve any page as image or SVG, to obtain the text using SVG or OCR, use the annotations or the document structure such as links and bookmarks.

After the document is obtained, InternalObject will be to the internal LEADTOOLS object used with the document.

Refer to Loading Using LEADTOOLS Document Library for detailed information on how to use this method and the various options used.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
 
public void DocumentFactoryLoadFromUriAsyncExample() 
{ 
	AutoResetEvent finished = null; 
	EventHandler<LoadAsyncCompletedEventArgs> completed = null; 
 
	completed = (sender, e) => 
	{ 
	 //Assert((int)e.UserState == 1); 
 
	 if (e.Cancelled) 
			Console.WriteLine("Canceled"); 
		if (e.Error != null) 
			Console.WriteLine("Error:" + e.Error.Message); 
		if (e.Document == null) 
			Console.WriteLine("Document is null"); 
 
		var thisOptions = sender as LoadDocumentAsyncOptions; 
		thisOptions.Completed -= completed; 
 
		if (e.Document != null) 
		{ 
			PrintOutDocumentInfo(e.Document); 
		} 
 
		finished.Set(); 
		Console.WriteLine("Done"); 
	}; 
 
	var options = new LoadDocumentAsyncOptions(); 
	options.Completed += completed; 
 
	finished = new AutoResetEvent(false); 
	DocumentFactory.LoadFromUriAsync(new Uri("http://localhost/Leadtools.pdf"), options); 
	finished.WaitOne(); 
} 
 
 
public void PrintOutDocumentInfo(LEADDocument document) 
{ 
	Console.WriteLine("General"); 
	Console.WriteLine("  DocumentId:" + document.DocumentId); 
	if (document.Uri != null) 
		Console.WriteLine("  Uri:" + document.Uri); 
	Console.WriteLine("  Name:" + document.Name); 
	Console.WriteLine("  CacheStatus:" + document.CacheStatus); 
	Console.WriteLine("  LastCacheSyncTime:" + document.LastCacheSyncTime); 
	Console.WriteLine("  IsReadOnly:" + document.IsReadOnly); 
	Console.WriteLine("  IsLocal:" + document.IsLocal); 
	Console.WriteLine("  MimeType:" + document.MimeType); 
	Console.WriteLine("  IsEncrypted:" + document.IsEncrypted); 
	Console.WriteLine("  IsDecrypted:" + document.IsDecrypted); 
	Console.WriteLine("  UserData:" + document.UserData); 
	Console.WriteLine("Cache"); 
	Console.WriteLine("  HasCache:" + document.HasCache); 
	Console.WriteLine("  AutoDeleteFromCache:" + document.AutoDeleteFromCache); 
	Console.WriteLine("Metadata"); 
	foreach (var item in document.Metadata) 
		Console.WriteLine("  {0} {1}", item.Key, item.Value); 
 
	Console.WriteLine("Documents"); 
	Console.WriteLine("  Count:" + document.Documents.Count); 
	foreach (var childDocument in document.Documents) 
	{ 
		Console.WriteLine("    Name:" + childDocument.Name); 
	} 
 
	Console.WriteLine("Pages"); 
	Console.WriteLine("  Count:" + document.Pages.Count); 
 
	for (var pageNumber = 1; pageNumber <= document.Pages.Count; pageNumber++) 
	{ 
		var page = document.Pages[pageNumber - 1]; 
 
		Console.WriteLine("    PageNumber:" + pageNumber); 
		Console.WriteLine("      OriginalPageNumber:" + page.OriginalPageNumber); 
		Console.WriteLine("      OriginalDocumentName:" + page.Document.Name); 
		Console.WriteLine("      Size:{0}", page.Size); 
	} 
 
	Console.WriteLine("--------"); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Document.Writer 
Imports Leadtools.Svg 
Imports Leadtools.Document 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Engine 
Imports Leadtools.Barcode 
Imports Leadtools.Ocr 
Imports LeadtoolsDocumentExamples.LeadtoolsExamples.Common 
Imports Leadtools.Document.Converter 
 
Public Shared Sub DocumentFactoryLoadFromUriAsyncExample() 
   Dim finished As AutoResetEvent = Nothing 
   Dim completed As EventHandler(Of LoadAsyncCompletedEventArgs) = Nothing 
 
   completed = 
      Sub(sender, e) 
         'Assert((int)e.UserState = 1); 
 
         If e.Cancelled Then 
            Console.WriteLine("Canceled") 
         End If 
         If Not e.Error Is Nothing Then 
            Console.WriteLine("Error:" & e.Error.Message) 
         End If 
         If e.Document Is Nothing Then 
            Console.WriteLine("Document is null") 
         End If 
 
         Dim thisOptions As LoadDocumentAsyncOptions = TryCast(sender, LoadDocumentAsyncOptions) 
         RemoveHandler thisOptions.Completed, completed 
 
         If Not e.Document Is Nothing Then 
            PrintOutDocumentInfo(e.Document) 
         End If 
 
         finished.Set() 
         Console.WriteLine("Done") 
      End Sub 
 
   Dim options As New LoadDocumentAsyncOptions() 
   AddHandler options.Completed, completed 
 
   finished = New AutoResetEvent(False) 
   DocumentFactory.LoadFromUriAsync(New Uri("http://localhost/Leadtools.pdf"), options) 
   finished.WaitOne() 
End Sub 
 
Public Shared Sub PrintOutDocumentInfo(ByVal document As LEADDocument) 
   Console.WriteLine("General") 
   Console.WriteLine("  DocumentId:" + document.DocumentId) 
   If Not IsNothing(document.Uri) Then 
      Console.WriteLine("  Uri:" + document.Uri.ToString()) 
   Else 
      Console.WriteLine("  Name:" + document.Name) 
   End If 
 
   Console.WriteLine("  CacheStatus:" + document.CacheStatus.ToString()) 
   Console.WriteLine("  LastCacheSyncTime:" + document.LastCacheSyncTime.ToString()) 
   Console.WriteLine("  IsReadOnly:" + document.IsReadOnly.ToString()) 
   Console.WriteLine("  IsLocal:" + document.IsLocal.ToString()) 
   Console.WriteLine("  MimeType:" + document.MimeType) 
   Console.WriteLine("  IsEncrypted:" + document.IsEncrypted.ToString()) 
   Console.WriteLine("  IsDecrypted:" + document.IsDecrypted.ToString()) 
   If Not IsNothing(document.UserData) Then 
      Console.WriteLine("  UserData:" + document.UserData.ToString()) 
   End If 
   Console.WriteLine("Cache") 
   Console.WriteLine("  HasCache:" + document.HasCache.ToString()) 
   Console.WriteLine("  AutoDeleteFromCache:" + document.AutoDeleteFromCache.ToString()) 
   Console.WriteLine("Metadata") 
   For Each item As KeyValuePair(Of String, String) In document.Metadata 
      Console.WriteLine("  {0} {1}", item.Key, item.Value) 
   Next 
 
   Console.WriteLine("Documents") 
   Console.WriteLine("  Count:" + document.Documents.Count.ToString()) 
   For Each childDocument As LEADDocument In document.Documents 
      Console.WriteLine("    Name:" + childDocument.Name) 
   Next 
 
   Console.WriteLine("Pages") 
   Console.WriteLine("  Count:" + document.Pages.Count.ToString()) 
 
   For pageNumber As Integer = 1 To document.Pages.Count 
      Dim page As Leadtools.Document.DocumentPage = document.Pages(pageNumber - 1) 
 
      Console.WriteLine("    PageNumber:" + pageNumber.ToString()) 
      Console.WriteLine("      OriginalPageNumber:" + page.OriginalPageNumber.ToString()) 
      Console.WriteLine("      OriginalDocumentName:" + page.Document.Name) 
      Console.WriteLine("      Size:{0}", page.Size.ToString()) 
   Next 
 
   Console.WriteLine("--------") 
End Sub 
Requirements
Target Platforms
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.