←Select platform

Clone Method

Summary

Clones this document in the specified cache.

Syntax
C#
VB
C++
Public Function Clone( 
   ByVal cache As ObjectCache, 
   ByVal options As CloneDocumentOptions 
) As LEADDocument 

Parameters

cache

Destination cache. This value cannot be null.

options

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

Return Value

A brand new document that is an exact copy of this LEADDocument.

Remarks

This method creates a brand new document that is an exact copy of this object and stores it in the cache. A copy of all the document properties and data is created and the resulting object is independent of this document. In other words, the user can delete this LEADDocument after Clone returns and the resulting document returned by the method will be 100% functional.

Clone creates a new document in targetCache and the user can get the cache of the current document using GetCache to clone the document in the same cache. The policy set in CloneDocumentOptions.CachePolicy is used for the items of the newly created document or uses a default policy if the value is null.

The newly created document will use the ID set in CloneDocumentOptions.DocumentId. If this value is null, then the document will use DocumentFactory.NewCacheId to obtain a brand new unique document ID and use it instead. The ID is set in the DocumentId value of the new document.

Example

This example loads a document into the cache and then clones it.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public static 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(); 
      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(); 
      } 
   } 
 
   // 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); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Document.Writer 
Imports Leadtools.Svg 
Imports Leadtools.Document 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Engine 
Imports Leadtools.Barcode 
Imports Leadtools.Ocr 
Imports LeadtoolsDocumentExamples.LeadtoolsExamples.Common 
Imports Leadtools.Document.Converter 
 
Public Shared Sub CloneDocumentExample() 
   Dim documentUri As New Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf") 
 
   ' Setup a cache 
   Dim cache As New FileCache() 
   cache.CacheDirectory = "c:\cache-dir" 
 
   Dim documentId1 As String 
   Dim documentId2 As String 
 
   ' Load a document into the cache 
   Dim loadDocumentOptions As New LoadDocumentOptions() 
   loadDocumentOptions.Cache = cache 
   Using document1 As LEADDocument = 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 
      Dim cloneDocumentOptions As New CloneDocumentOptions() 
      Using document2 As LEADDocument = document1.Clone(cache, cloneDocumentOptions) 
         ' Get its document ID And save it 
         documentId2 = document2.DocumentId 
         document2.AutoDeleteFromCache = False 
         document2.AutoSaveToCache = False 
         document2.SaveToCache() 
      End Using 
   End Using 
 
   ' Ensure both documents are in the cache 
   Dim cacheInfo As DocumentCacheInfo 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId1) 
   Debug.Assert(Not IsNothing(cacheInfo)) 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId2) 
   Debug.Assert(Not IsNothing(cacheInfo)) 
 
   ' Now delete the first document 
   Dim deleteFromCacheOptions As New LoadFromCacheOptions 
   deleteFromCacheOptions.Cache = cache 
   deleteFromCacheOptions.DocumentId = documentId1 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions) 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId1) 
   Debug.Assert(IsNothing(cacheInfo)) 
 
   ' Or by loading it from the cache, it should be null 
   Dim loadFromCacheOptions As New LoadFromCacheOptions 
   loadFromCacheOptions.Cache = cache 
   loadFromCacheOptions.DocumentId = documentId1 
   Using document1 As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions) 
      Debug.Assert(IsNothing(document1)) 
   End Using 
 
   ' And ensure that the cloned document Is still usable by loading it 
   loadFromCacheOptions = New LoadFromCacheOptions 
   loadFromCacheOptions.Cache = cache 
   loadFromCacheOptions.DocumentId = documentId2 
   Using document2 As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions) 
      Debug.Assert(Not IsNothing(document2)) 
   End Using 
 
   ' We are done, delete it 
   deleteFromCacheOptions = New LoadFromCacheOptions 
   deleteFromCacheOptions.Cache = cache 
   deleteFromCacheOptions.DocumentId = documentId2 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions) 
End Sub 

Requirements

Target Platforms

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

Leadtools.Document Assembly