←Select platform

DocumentFactory Class

Summary

Provides support for loading and creating Document objects as well as managing the global cache.

Syntax
C#
C++/CLI
Java
Python
public static class DocumentFactory 
public ref class DocumentFactory sealed abstract 
public final class DocumentFactory 
class DocumentFactory: 
Remarks

The main class used for the LEADTOOLS Document class library is LEADDocument. This class abstracts the internal implementation to provide unified properties and methods to access the internal document. Users can create a new document or load existing documents from disk file or a URL.

Documents cannot be created directly. Instead, use the static DocumentFactory methods to obtain a LEADDocument instance, as follows:

Member Description

LoadFromFile

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

LoadFromUri

Loads a document from existing data stored in a remote URI.

LoadFromUriAsync

Loads a document asynchronously from an existing data stored in remote URI.

LoadFromStream

Loads a document from existing data stored in a stream.

Create
Creates a new empty virtual document.
MimeTypes
MIME type whitelisting support.

RasterCodecsTemplate

Global template used when loading and saving raster and SVG images.

These methods, when combined with the ObjectCache, provide the following extra functionality:

Member Description

Cache

The global LEADTOOLS ObjectCache object responsible for managing cache items and expiration policies. The cache can be stored in this value (if the system requires the use of a single global cache) or a new instance is passed directly to the various uploading, loading and saving methods to use distinct or shared caches with each document.

Create

Creates a new empty document.

LoadFromCache

Loads a previously saved document from the cache.

DocumentFactory

Deletes a document from the cache.

GetDocumentCacheInfo

Retrieves information about a document in the cache.

BeginUpload, UploadDocument, UploadAnnotations and AbortUploadDocument

Supports uploading a document to the cache system used by the factory.

DownloadDocument and DownloadAnnotations

Supports uploading a document to the cache system used by the factory.

CloneDocument

Clones (creates a copy) of an existing document in the cache.

Example
C#
Java
using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
 
 
public void DocumentFactoryExample() 
{ 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), 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:\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 documentFactoryExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"), options); 
   assertTrue(document != null); 
   printOutDocumentInfo(document); 
   System.out.println("Document created successfully"); 
   document.dispose(); 
} 
 
public void printOutDocumentInfo(LEADDocument document) { 
   System.out.println("General"); 
   System.out.println("  DocumentId:" + document.getDocumentId()); 
 
   if (document.getUri() != null) 
      System.out.println("  Uri:" + document.getUri()); 
   System.out.println("  Name:" + document.getName()); 
   System.out.println("  CacheStatus:" + document.getCacheStatus()); 
   System.out.println("  LastCacheSyncTime:" + document.getLastCacheSyncTime()); 
   System.out.println("  IsReadOnly:" + document.isReadOnly()); 
   System.out.println("  IsLocal:" + document.isLocal()); 
   System.out.println("  MimeType:" + document.getMimeType()); 
   System.out.println("  IsEncrypted:" + document.isEncrypted()); 
   System.out.println("  IsDecrypted:" + document.isDecrypted()); 
   System.out.println("  UserData:" + document.getUserData()); 
   System.out.println("Cache"); 
   System.out.println("  HasCache:" + document.hasCache()); 
   System.out.println("  AutoDeleteFromCache:" + document.getAutoDeleteFromCache()); 
   System.out.println("Metadata"); 
   Object[] keys = document.getMetadata().keySet().toArray(); 
   Object[] values = document.getMetadata().values().toArray(); 
   for (int i = 0; i < keys.length; i++) { 
      System.out.println("  " + keys[i] + " " + values[i]); 
   } 
   System.out.println("Documents"); 
   System.out.println("  Count:" + document.getDocuments().size()); 
   for (LEADDocument childDocument : document.getDocuments()) { 
      System.out.println("    Name:" + childDocument.getName()); 
   } 
   System.out.println("Pages"); 
   System.out.println("  Count:" + document.getPages().size()); 
   for (int pageNumber = 1; pageNumber <= document.getPages().size(); pageNumber++) { 
      DocumentPage page = document.getPages().get(pageNumber - 1); 
 
      System.out.println("    PageNumber:" + pageNumber); 
      System.out.println("      OriginalPageNumber:" + page.getOriginalPageNumber()); 
      System.out.println("      OriginalDocumentName:" + page.getDocument().getName()); 
      System.out.println("      Size:" + page.getSize()); 
   } 
   System.out.println("--------"); 
   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.