←Select platform

LoadFromFile Method

Summary

Loads a document from existing data stored in a disk file.

Syntax
C#
C++/CLI
Java
Python
public static LEADDocument LoadFromFile( 
   string fileName, 
   LoadDocumentOptions options 
) 
public:  
   static LEADDocument^ LoadFromFile( 
      String^ fileName, 
      LoadDocumentOptions^ options 
   ) 
public static Document loadFromFile(String fileName, LoadDocumentOptions options) 
def LoadFromFile(self,fileName,options): 

Parameters

fileName

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

options

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

Return Value

The newly created document object.

Remarks

This method may use the cache if the related cache options are set. If the cache is used and neither the LoadDocumentOptions.Cache property nor the Cache property was set up with a valid cache object, this method will throw an exception.

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

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

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

Example
C#
Java
using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
 
 
public void DocumentFactoryLoadFromFileExample() 
{ 
   var options = new LoadDocumentOptions(); 
   options.AnnotationsUri = null; 
   options.FirstPageNumber = 1; 
   options.LastPageNumber = -1; 
   options.Password = null; 
   options.WebClient = null; 
   options.CachePolicy = new CacheItemPolicy(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), options)) 
   { 
      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 documentFactoryLoadFromFileExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   options.setAnnotationsUri(null); 
   options.setFirstPageNumber(1); 
   options.setLastPageNumber(-1); 
   options.setPassword(null); 
   options.setCachePolicy(new CacheItemPolicy()); 
   LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"), options); 
   printOutDocumentInfo(document); 
   assertTrue(document != null); 
   System.out.println("Document created successfully"); 
   document.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.