Clones (creates a copy) of an uploaded document in the cache.
public static Uri CloneDocument(
ObjectCache sourceCache,
ObjectCache targetCache,
Uri sourceDocumentUri,
CloneDocumentOptions options
)
Public Shared Function CloneDocument(
ByVal sourceCache As ObjectCache,
ByVal targetCache As ObjectCache,
ByVal sourceDocumentUri As Uri,
ByVal options As CloneDocumentOptions
) As Uri
public:
static Uri^ CloneDocument(
ObjectCache^ sourceCache,
ObjectCache^ targetCache,
Uri^ sourceDocumentUri,
CloneDocumentOptions^ options
)
sourceCache
The cache object containing the data for the source document. This value must not be null.
targetCache
The cache object that will contain the data for the destination document. This value must not be null and can be the same value as sourceCache to clone in the document in the same cache.
sourceDocumentUri
URI to the data of the source document in the cache. This must be in the format of an uploaded document in the cache (leadcache://documentId).
options
Options to use during cloning.
The URL to the uploaded data of the new newly created document if successful. This value is in the leadcache://documentId format.
This method can be used to clone the data of an uploaded document in the same or a separate cache.
This method performs the following:
Calls BeginUpload on the targetCache using DocumentId and CachePolicy of options.
Repeatedly calls DownloadDocument on sourceCache and UploadDocument on targetCache to download the document data from the source and upload it into the destination.
Repeatedly calls DownloadAnnotations on sourceCache and UploadAnnotations on targetCache to download the annotation data (if any) from the source and upload it into the destination.
Calls EndUpload on targetCache when done.
Returns the URL to the newly uploaded document in targetCache.
Use CloneDocument(ObjectCache,ObjectCache,string,CloneDocumentOptions) or CloneDocument(ObjectCache,string,CloneDocumentOptions) to clone an existing document in the same cache.
This example uploads a document into the cache and then makes a clone of the data.
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 FactoryCloneDocumentExample()
{
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 in the cache
var cloneDocumentOptions = new CloneDocumentOptions();
using (var document2 = DocumentFactory.CloneDocument(cache, documentId1, 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, clean up
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 FactoryCloneDocumentExample()
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()
End Using
' Clone it into the same cache
Dim cloneDocumentOptions As New CloneDocumentOptions()
Using document2 As LEADDocument = DocumentFactory.CloneDocument(cache, documentId1, cloneDocumentOptions)
' Get its document ID And save it
documentId2 = document2.DocumentId
document2.AutoDeleteFromCache = False
document2.AutoSaveToCache = False
document2.SaveToCache()
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 loadFromCacheOptions As New LoadFromCacheOptions
loadFromCacheOptions.Cache = cache
loadFromCacheOptions.DocumentId = documentId1
DocumentFactory.DeleteFromCache(loadFromCacheOptions)
cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId1)
Debug.Assert(IsNothing(cacheInfo))
' Or by loading it from the cache, it should be null
loadFromCacheOptions = 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
Dim deleteFromCacheOptions As New LoadFromCacheOptions
deleteFromCacheOptions.Cache = cache
deleteFromCacheOptions.DocumentId = documentId2
DocumentFactory.DeleteFromCache(deleteFromCacheOptions)
End Sub
CloneDocument(ObjectCache,string,CloneDocumentOptions)
CloneDocument(ObjectCache,ObjectCache,string,CloneDocumentOptions)
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document