←Select platform

LoadFromStream Method

Summary

Loads a document from existing data stored in a stream.

Syntax
C#
C++/CLI
Java
Python
public static LEADDocument LoadFromStream( 
   Stream stream, 
   LoadDocumentOptions options 
) 
public:  
   static LEADDocument^ LoadFromStream( 
      System::IO::Stream^ stream, 
      LoadDocumentOptions^ options 
   ) 
public static Document loadFromStream(InputStream stream, LoadDocumentOptions options) 
def LoadFromStream(self,stream,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#
Java
using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
 
 
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)) 
      { 
         Console.WriteLine(document.Stream); 
         PrintOutDocumentInfo(document); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.util.Calendar; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.caching.*; 
import leadtools.document.*; 
 
 
public void documentFactoryLoadFromStreamExample() throws FileNotFoundException { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // Get a stream to anything, in this case a file 
   // Note that the stream must be seekable 
   String fileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
   ILeadStream documentStream = LeadStreamFactory.create(fileName); 
   // We must keep the stream alive as long as the document is alive 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   documentStream.seek(LeadSeekOrigin.BEGIN, 0); 
   LEADDocument document = DocumentFactory.loadFromStream(documentStream, options); 
   System.out.println(document.toString()); 
   printOutDocumentInfo(document); 
   assertTrue(document != null && documentStream != null); 
   System.out.println("Document and DocumentStream created successfully"); 
   document.dispose(); 
   documentStream.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.