Downloads the data of the specified document ID.
public static long DownloadDocument(DownloadDocumentOptions options)
Public Shared Function DownloadDocument(ByVal options As DownloadDocumentOptions) As Long
public:static Int64 DownloadDocument(DownloadDocumentOptions^ options)
options
Options containing the document properties and download options to use. This value must not be null.
The total number of bytes read into DownloadDocumentOptions.Data or DownloadDocumentOptions.Stream. This can be less than the number of bytes requested by DownloadDocumentOptions.Length, if that many bytes are not currently available, or zero (0) if the end of the data has been reached.
Similar to UploadDocument, data can be downloaded in chunks or all at once. Refer to Uploading Using the Document Library for detailed information on how to use these methods and the various options used.
GetDocumentCacheInfo can be used to determine if a document is in the cache and to get its information.
DownloadAnnotations can be used to download the annotations of a document (if any).
This example will show how to download the data of a document stored in the cache into a stream all at once and then buffer array using chunks.
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 DownloadDocumentExample(){var documentUri = new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf");string documentFile1 = Path.Combine(ImagesPath.Path, "downloaded1.pdf");string documentFile2 = Path.Combine(ImagesPath.Path, "downloaded2.pdf");// Setup a cacheFileCache cache = new FileCache();cache.CacheDirectory = @"c:\cache-dir";string documentId;// Load a document into the cachevar loadDocumentOptions = new LoadDocumentOptions();loadDocumentOptions.Cache = cache;using (var document = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)){// Get its document ID and save itdocumentId = document.DocumentId;document.AutoDeleteFromCache = false;document.AutoSaveToCache = false;document.SaveToCache();}// Now download it all at once into a memory streamvar downloadDocumentOptions = new DownloadDocumentOptions();downloadDocumentOptions.Cache = cache;downloadDocumentOptions.DocumentId = documentId;downloadDocumentOptions.Offset = 0;downloadDocumentOptions.Length = -1;using (var stream = new MemoryStream()){downloadDocumentOptions.Stream = stream;long bytes = DocumentFactory.DownloadDocument(downloadDocumentOptions);Console.WriteLine("Downloaded {0} bytes into the stream", bytes);// Save the stream to a file and show itusing (var output = File.Create(documentFile1))stream.WriteTo(output);Process.Start(documentFile1);}// Download it again, this time we will buffer it 32K at a timedownloadDocumentOptions = new DownloadDocumentOptions();downloadDocumentOptions.Cache = cache;downloadDocumentOptions.DocumentId = documentId;byte[] buffer = new byte[1024 * 32];using (var output = File.Create(documentFile2)){// Offset to where we are:long offset = 0;int bytes;do{downloadDocumentOptions.Offset = offset;downloadDocumentOptions.Length = buffer.Length;downloadDocumentOptions.Data = buffer;downloadDocumentOptions.DataOffset = 0;bytes = (int)DocumentFactory.DownloadDocument(downloadDocumentOptions);if (bytes > 0){Console.WriteLine("Downloaded {0} bytes into the buffer", bytes);// Next chunkoffset += bytes;output.Write(buffer, 0, bytes);}}while (bytes > 0);}Process.Start(documentFile2);// We are done, clean upvar deleteFromCacheOptions = new LoadFromCacheOptions();deleteFromCacheOptions.Cache = cache;deleteFromCacheOptions.DocumentId = documentId;DocumentFactory.DeleteFromCache(deleteFromCacheOptions);}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.BarcodeImports Leadtools.OcrImports LeadtoolsDocumentExamples.LeadtoolsExamples.CommonImports Leadtools.Document.ConverterPublic Shared Sub DownloadDocumentExample()Dim documentUri As New Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf")Dim documentFile1 As String = Path.Combine(ImagesPath.Path, "downloaded1.pdf")Dim documentFile2 As String = Path.Combine(ImagesPath.Path, "downloaded2.pdf")' Setup a cacheDim cache As New FileCache()cache.CacheDirectory = "c:\cache-dir"Dim documentId As String' Load a document into the cacheDim loadDocumentOptions As New LoadDocumentOptions()loadDocumentOptions.Cache = cacheUsing document As LEADDocument = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)' Get its document ID And save itdocumentId = document.DocumentIddocument.AutoDeleteFromCache = Falsedocument.AutoSaveToCache = Falsedocument.SaveToCache()End Using' Now download it all at once into a memory streamDim downloadDocumentOptions As New DownloadDocumentOptions()downloadDocumentOptions.Cache = cachedownloadDocumentOptions.DocumentId = documentIddownloadDocumentOptions.Offset = 0downloadDocumentOptions.Length = -1Using stream As New MemoryStream()downloadDocumentOptions.Stream = streamDim bytes As Long = DocumentFactory.DownloadDocument(downloadDocumentOptions)Console.WriteLine("Downloaded {0} bytes into the stream", bytes)' Save the stream to a file And show itUsing output As Stream = File.Create(documentFile1)stream.WriteTo(output)End UsingProcess.Start(documentFile1)End Using' Download it again, this time we will buffer it 32K at a timedownloadDocumentOptions = New DownloadDocumentOptions()downloadDocumentOptions.Cache = cachedownloadDocumentOptions.DocumentId = documentIdDim buffer((1024 * 32) - 1) As ByteUsing output As Stream = File.Create(documentFile2)' Offset to where we areDim offset As Long = 0Dim bytes As IntegerDodownloadDocumentOptions.Offset = offsetdownloadDocumentOptions.Length = buffer.LengthdownloadDocumentOptions.Data = bufferdownloadDocumentOptions.DataOffset = 0bytes = CType(DocumentFactory.DownloadDocument(downloadDocumentOptions), Integer)If bytes > 0 ThenConsole.WriteLine("Downloaded {0} bytes into the buffer", bytes)' Next chunkoffset += bytesoutput.Write(buffer, 0, bytes)End IfLoop While bytes > 0End UsingProcess.Start(documentFile2)' We are done, clean upDim deleteFromCacheOptions As New LoadFromCacheOptionsdeleteFromCacheOptions.Cache = cachedeleteFromCacheOptions.DocumentId = documentIdDocumentFactory.DeleteFromCache(deleteFromCacheOptions)End Sub
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
