←Select platform

CloneDocument(ObjectCache,string,CloneDocumentOptions) Method

Summary

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

Syntax
C#
C++/CLI
Python
public static LEADDocument CloneDocument( 
   ObjectCache cache, 
   string documentId, 
   CloneDocumentOptions options 
) 
public:  
   static LEADDocument^ CloneDocument( 
      ObjectCache^ cache, 
      String^ documentId, 
      CloneDocumentOptions^ options 
   ) 
def CloneDocument(self,options): 

Parameters

cache

Cache containing the existing and new document. This value must not be null.

documentId

ID of the document to clone. This value must not be null and must be the ID of an existing document in cache.

options

Options to use during cloning.

Return Value

A brand new document that is an exact copy of the document referenced by documentId.

Remarks

This method performs the following:

  1. Loads the document from the cache using LoadFromCache passing cache and documentId.

  2. Calls LEADDocument.Clone on the resulting object and returns the created document.

Refer to LEADDocument.Clone for more information.

Use CloneDocument(ObjectCache,ObjectCache,Uri,CloneDocumentOptions) to clone an uploaded document.

Example
C#
Java
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); 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
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.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void leadDocumentCloneDocumentExample() throws URISyntaxException { 
   URI documentUri = new URI("https://demo.leadtools.com/images/pdf/leadtools.pdf"); 
 
   // Setup a cache 
   FileCache cache = new FileCache(); 
   cache.setCacheDirectory("c:\\cache-dir"); 
 
   String documentId1; 
   String documentId2; 
 
   // Load a document into the cache 
   LoadDocumentOptions loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.setCache(cache); 
   LEADDocument document1 = DocumentFactory.loadFromUri(documentUri, loadDocumentOptions); 
 
   // Get its document ID and save it 
   documentId1 = document1.getDocumentId(); 
   document1.setAutoDeleteFromCache(false); 
   document1.setAutoSaveToCache(false); 
   document1.saveToCache(); 
 
   // Clone it into the same cache 
   CloneDocumentOptions cloneDocumentOptions = new CloneDocumentOptions(); 
 
   System.out.println("Cache Policy: " + cloneDocumentOptions.getCachePolicy().getAbsoluteExpiration()); 
 
   LEADDocument document2 = document1.clone(cache, cloneDocumentOptions); 
 
   // Get its document ID and save it 
   documentId2 = document2.getDocumentId(); 
   document2.setAutoDeleteFromCache(false); 
   document2.setAutoSaveToCache(false); 
   document2.saveToCache(); 
 
   LEADDocument document3 = DocumentFactory.cloneDocument(cache, documentId1, cloneDocumentOptions); 
 
   // Get its document ID and save it 
   documentId1 = document3.getDocumentId(); 
   document3.setAutoDeleteFromCache(false); 
   document3.setAutoSaveToCache(false); 
   document3.saveToCache(); 
 
   // Ensure both documents are in the cache 
   DocumentCacheInfo cacheInfo; 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId1); 
   assertTrue(cacheInfo != null); 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId2); 
   assertTrue(cacheInfo != null); 
 
   // Now delete the first document 
   LoadFromCacheOptions deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.setCache(cache); 
   deleteFromCacheOptions.setDocumentId(documentId1); 
   DocumentFactory.deleteFromCache(deleteFromCacheOptions); 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId1); 
   assertTrue(cacheInfo == null); 
 
   // Or by loading it from the cache, it should be null 
   LoadFromCacheOptions loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(documentId1); 
   document1 = DocumentFactory.loadFromCache(loadFromCacheOptions); 
 
   assertTrue(document1 == null); 
 
   // And ensure that the cloned document is still usable by loading it 
   loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(documentId2); 
   document2 = DocumentFactory.loadFromCache(loadFromCacheOptions); 
 
   assertTrue(document2 != null); 
 
   // We are done, delete it 
   deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.setCache(cache); 
   deleteFromCacheOptions.setDocumentId(documentId2); 
   DocumentFactory.deleteFromCache(deleteFromCacheOptions); 
} 
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.