Options to use for automatically uploading the converted document to the cache.
public UploadDocumentOptions UploadDocumentOptions { get; set; } Public Property UploadDocumentOptions() As UploadDocumentOptionsGetSet
public:property UploadDocumentOptions^ UploadDocumentOptions{UploadDocumentOptions^ get()void set(UploadDocumentOptions^ value)}
Options to use for automatically upload the converted document to the cache. Default value is null.
One output must be specified for the conversion to be successful: One of OutputAnnotationsFileName, OutputDocumentStream or UploadDocumentOptions must not be null.
If UploadDocumentUri is specified, then DocumentConverter will perform the following:
Convert the document as usual to either a temporary file or stream depending on the value of RasterDefaults.TempFileMode.
If the conversion is successful, the converter will then upload the result document using uploadDocumentOptions to upload the document to the cache. The uploaded document URI will be stored in DocumentConverterJob.UploadDocumentUri.
The following example will save a document to the cache, then convert it and automatically upload it.
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.Document.Converter;public static void UploadToCacheExample(){// We will be converting this TIFF file to PDFstring imageUrl = "https://demo.leadtools.com/images/tiff/ocr.tif";// Download the final document to this filestring outputFile = @"c:\temp\output.pdf";string inputDocumentId = null;Uri outputDocumentUrl = null;// Setup the cacheFileCache cache = new FileCache();cache.CacheDirectory = @"c:\temp\cache";// Load the document and save it to the cachevar loadDocumentOptions = new LoadDocumentOptions();loadDocumentOptions.Cache = cache;Console.WriteLine("Saving input document into the cache");using (LEADDocument document = DocumentFactory.LoadFromUri(new Uri(imageUrl), loadDocumentOptions)){// Store the document ID to use it laterinputDocumentId = document.DocumentId;// Make sure the document persist on the cache after we dispose itdocument.AutoSaveToCache = false;document.AutoDeleteFromCache = false;document.SaveToCache();}// Convert the document to PDF and automatically upload itusing (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)){ocrEngine.Startup(null, null, null, null);using (var documentConverter = new DocumentConverter()){documentConverter.SetOcrEngineInstance(ocrEngine, false);var jobData = new DocumentConverterJobData();// InputjobData.DocumentId = inputDocumentId;jobData.Cache = cache;// Output, upload to the same cache as a new documentvar uploadDocumentOptions = new UploadDocumentOptions();uploadDocumentOptions.Cache = cache;jobData.UploadDocumentOptions = uploadDocumentOptions;// OptionsjobData.DocumentFormat = DocumentFormat.Pdf;// RunConsole.WriteLine("Converting {0} and uploading", inputDocumentId);var job = documentConverter.Jobs.CreateJob(jobData);documentConverter.Jobs.RunJob(job);Console.WriteLine(job.Status);if (job.Status != DocumentConverterJobStatus.Aborted){Console.WriteLine("Downloading {0}", job.UploadDocumentUri);// Download it from the cache to the output fileusing (var stream = File.Create(outputFile)){var downloadDocumentOptions = new DownloadDocumentOptions();downloadDocumentOptions.Cache = cache;downloadDocumentOptions.DocumentId = job.UploadDocumentUri.ToString();downloadDocumentOptions.Offset = 0;downloadDocumentOptions.Length = -1;downloadDocumentOptions.Stream = stream;DocumentFactory.DownloadDocument(downloadDocumentOptions);}outputDocumentUrl = job.UploadDocumentUri;Process.Start(outputFile);}}}// Clean upvar deleteFromCacheOptions = new LoadFromCacheOptions();deleteFromCacheOptions.Cache = cache;if (inputDocumentId != null){deleteFromCacheOptions.DocumentId = inputDocumentId;DocumentFactory.DeleteFromCache(deleteFromCacheOptions);}if (outputDocumentUrl != null){deleteFromCacheOptions.DocumentId = outputDocumentUrl.ToString();DocumentFactory.DeleteFromCache(deleteFromCacheOptions);}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.OcrImports Leadtools.Document.ConverterImports LeadtoolsDocumentConverterExamples.LeadtoolsExamples.CommonPublic Shared Sub UploadToCacheExample()' We will be converting this TIFF file to PDFDim imageUrl As String = "https://demo.leadtools.com/images/tiff/ocr.tif"' Download the final document to this fileDim outputFile As String = "c:\temp\output.pdf"Dim inputDocumentId As String = NothingDim outputDocumentUrl As Uri = Nothing' Setup the cacheDim cache As New FileCache()cache.CacheDirectory = "c:\temp\cache"' Load the document And save it to the cacheDim loadDocumentOptions As New LoadDocumentOptions()loadDocumentOptions.Cache = cacheConsole.WriteLine("Saving input document into the cache")Using document As LEADDocument = DocumentFactory.LoadFromUri(New Uri(imageUrl), loadDocumentOptions)' Store the document ID to use it laterinputDocumentId = document.DocumentId' Make sure the document persist on the cache after we dispose itdocument.AutoSaveToCache = Falsedocument.AutoDeleteFromCache = Falsedocument.SaveToCache()End Using' Convert the document to PDF And automatically upload itUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)Using documentConverter As New DocumentConverter()documentConverter.SetOcrEngineInstance(ocrEngine, False)Dim jobData As New DocumentConverterJobData()' InputjobData.DocumentId = inputDocumentIdjobData.Cache = cache' Output, upload to the same cache as a New documentDim uploadDocumentOptions As New UploadDocumentOptions()uploadDocumentOptions.Cache = cachejobData.UploadDocumentOptions = uploadDocumentOptions' OptionsjobData.DocumentFormat = DocumentFormat.Pdf' RunConsole.WriteLine("Converting {0} and uploading", inputDocumentId)Dim job As DocumentConverterJob = documentConverter.Jobs.CreateJob(jobData)documentConverter.Jobs.RunJob(job)Console.WriteLine(job.Status)If job.Status <> DocumentConverterJobStatus.Aborted ThenConsole.WriteLine("Downloading {0}", job.UploadDocumentUri)' Download it from the cache to the output fileUsing stream As Stream = File.Create(outputFile)Dim downloadDocumentOptions As New DownloadDocumentOptions()downloadDocumentOptions.Cache = cachedownloadDocumentOptions.DocumentId = job.UploadDocumentUri.ToString()downloadDocumentOptions.Offset = 0downloadDocumentOptions.Length = -1downloadDocumentOptions.Stream = streamDocumentFactory.DownloadDocument(downloadDocumentOptions)End UsingoutputDocumentUrl = job.UploadDocumentUriProcess.Start(outputFile)End IfEnd UsingEnd Using' Clean upDim deleteFromCacheOptions As New LoadFromCacheOptions()deleteFromCacheOptions.Cache = cacheIf Not inputDocumentId Is Nothing ThendeleteFromCacheOptions.DocumentId = inputDocumentIdDocumentFactory.DeleteFromCache(deleteFromCacheOptions)End IfIf Not outputDocumentUrl Is Nothing ThendeleteFromCacheOptions.DocumentId = outputDocumentUrl.ToString()DocumentFactory.DeleteFromCache(deleteFromCacheOptions)End IfEnd 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
