←Select platform

Is this page helpful?

In this page

LoadFromStream Method

Summary

Loads a document from existing data stored in a stream.

Syntax
C#
VB
C++
Java
public static LEADDocument LoadFromStream( 
   Stream stream, 
   LoadDocumentOptions options 
) 
Public Shared Function LoadFromStream( 
   ByVal stream As System.IO.Stream, 
   ByVal options As LoadDocumentOptions 
) As LEADDocument 
public:  
   static LEADDocument^ LoadFromStream( 
      System::IO::Stream^ stream, 
      LoadDocumentOptions^ options 
   ) 
public static Document loadFromStream(InputStream stream, LoadDocumentOptions options) 

Parameters

stream

Stream containing the original document data. This value cannot be null, and the stream must be seekable.

options

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

Return Value

The newly created document object.

Remarks

This method could use the cache and will throw an exception if neither LoadDocumentOptions.Cache nor Cache were set up with a valid cache object if certain options had been used.

LoadFromFile, LoadFromUri, LoadFromUriAsync and LoadFromStream all create 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, to use annotations, or to use document structures such as links and bookmarks.

The LEADDocument class will use the stream members to read the various parts, such as the images and metadata, on demand as needed. It is the user's responsibility to keep the stream alive while the document is not disposed. When the document is disposed, the stream is no longer used and can be closed or disposed by the user.

The value of stream will be stored in the LEADDocument.Stream property when this method successfully returns.

If the document is saved into the cache using SaveToCache, then the entire content of the stream is saved into the cache and the stream is no longer used and can be safely disposed by the user. When the document is later re-loaded from the cache using LoadFromCache, then it is treated as if it had been downloaded from an external resource and the stream functionality is not used (the value of Stream will be null).

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 DocumentFactoryLoadFromStreamExample() 
{ 
	// Get a stream to anything, in this case a file 
	// Note that the stream must be seekable 
	var fileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
	using (var stream = File.OpenRead(fileName)) 
	{ 
		// We must keep the stream alive as long as the document is alive 
		var options = new LoadDocumentOptions(); 
		using (var document = DocumentFactory.LoadFromStream(stream, options)) 
		{ 
			PrintOutDocumentInfo(document); 
		} 
	} 
} 
 
 
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("--------"); 
} 
 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
} 
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 DocumentFactoryLoadFromStreamExample() 
   ' Get a stream to anything, in this case a file 
   ' Note that the stream must be seekable 
   Dim fileName As String = Path.Combine(ImagesPath.Path, "Leadtools.pdf") 
   Using stream As Stream = File.OpenRead(fileName) 
      ' We must keep the stream alive as long as the document is alive 
      Dim options As New LoadDocumentOptions() 
      Using document As LEADDocument = DocumentFactory.LoadFromStream(stream, options) 
         PrintOutDocumentInfo(document) 
      End Using 
   End Using 
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.