←Select platform

DocumentId Property

Summary

The ID to be used for the created document.

Syntax
C#
C++/CLI
Python
public string DocumentId {get; set;} 
public:  
   property String^ DocumentId 
   { 
      String^ get() 
      void set(String^ value) 
   } 
DocumentId # get and set (CloneDocumentOptions) 

Property Value

String that specifies the ID to be used with the created document. The default value is null.

Remarks

When the value of DocumentId is null (the default), then the document factory will create a new unique ID using a GUID generator (DocumentFactory.NewCacheId). If the value is not null, then it is assumed to be a user-defined ID and used as is. In either case, the value is set in the LEADDocument.DocumentId property of the newly created document.

User-defined IDs can be used when the system already has unique IDs associated with the documents to be viewed. The document factory will neither check nor guarantee the uniqueness of these IDs.

Example
C#
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 CloneDocumentExample() 
{ 
   var documentUri = new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf"); 
 
   // Setup a cache 
   FileCache cache = new FileCache(); 
   cache.CacheDirectory = @"c:\cache-dir"; 
 
   string documentId1; 
   string documentId2; 
 
   // Load a document into the cache 
   var loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.Cache = cache; 
   using (var document1 = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)) 
   { 
      // Get its document ID and save it 
      documentId1 = document1.DocumentId; 
      document1.AutoDeleteFromCache = false; 
      document1.AutoSaveToCache = false; 
      document1.SaveToCache(); 
 
      // Clone it into the same cache 
      var cloneDocumentOptions = new CloneDocumentOptions(); 
 
      Console.WriteLine("Cache Policy: {0}", cloneDocumentOptions.CachePolicy.AbsoluteExpiration); 
 
      using (var document2 = document1.Clone(cache, cloneDocumentOptions)) 
      { 
         // Get its document ID and save it 
         documentId2 = document2.DocumentId; 
         document2.AutoDeleteFromCache = false; 
         document2.AutoSaveToCache = false; 
         document2.SaveToCache(); 
      } 
 
      using (var document3 = DocumentFactory.CloneDocument(cache, documentId1, cloneDocumentOptions)) 
      { 
         // Get its document ID and save it 
         documentId1 = document3.DocumentId; 
         document3.AutoDeleteFromCache = false; 
         document3.AutoSaveToCache = false; 
         document3.SaveToCache(); 
      } 
   } 
 
   // Ensure both documents are in the cache 
   DocumentCacheInfo cacheInfo; 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId1); 
   Debug.Assert(cacheInfo != null); 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId2); 
   Debug.Assert(cacheInfo != null); 
 
   // Now delete the first document 
   var deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.Cache = cache; 
   deleteFromCacheOptions.DocumentId = documentId1; 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions); 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId1); 
   Debug.Assert(cacheInfo == null); 
 
   // Or by loading it from the cache, it should be null 
   var loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.Cache = cache; 
   loadFromCacheOptions.DocumentId = documentId1; 
   using (var document1 = DocumentFactory.LoadFromCache(loadFromCacheOptions)) 
   { 
      Debug.Assert(document1 == null); 
   } 
 
   // And ensure that the cloned document is still usable by loading it 
   loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.Cache = cache; 
   loadFromCacheOptions.DocumentId = documentId2; 
   using (var document2 = DocumentFactory.LoadFromCache(loadFromCacheOptions)) 
   { 
      Debug.Assert(document2 != null); 
   } 
 
   // We are done, delete it 
   deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.Cache = cache; 
   deleteFromCacheOptions.DocumentId = documentId2; 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions); 
} 
Requirements

Target Platforms

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

Leadtools.Document Assembly

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