←Select platform

UploadDocumentOptions Property

Summary

Options to use for automatically uploading the converted document to the cache.

Syntax
C#
C++/CLI
Python
public UploadDocumentOptions UploadDocumentOptions { get; set; } 
public:  
   property UploadDocumentOptions^ UploadDocumentOptions 
   { 
      UploadDocumentOptions^ get() 
      void set(UploadDocumentOptions^ value) 
   } 
UploadDocumentOptions # get and set (DocumentConverterJobData) 

Property Value

Options to use for automatically upload the converted document to the cache. Default value is null.

Remarks

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.

Example

The following example will save a document to the cache, then convert it and automatically upload it.

C#
Java
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; 
using Leadtools.Annotations.Rendering; 
 
public static void UploadToCacheExample() 
{ 
   // We will be converting this TIFF file to PDF 
   string imageUrl = "https://demo.leadtools.com/images/tiff/ocr.tif"; 
   // Download the final document to this file 
   string outputFile = @"c:\temp\output.pdf"; 
   string inputDocumentId = null; 
   Uri outputDocumentUrl = null; 
 
   // Setup the cache 
   FileCache cache = new FileCache(); 
   cache.CacheDirectory = @"c:\temp\cache"; 
 
   // Load the document and save it to the cache 
   var 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 later 
      inputDocumentId = document.DocumentId; 
      // Make sure the document persist on the cache after we dispose it 
      document.AutoSaveToCache = false; 
      document.AutoDeleteFromCache = false; 
      document.SaveToCache(); 
   } 
 
   // Convert the document to PDF and automatically upload it 
   using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      ocrEngine.Startup(null, null, null, null); 
      using (var documentConverter = new DocumentConverter()) 
      { 
         documentConverter.SetOcrEngineInstance(ocrEngine, false); 
         var jobData = new DocumentConverterJobData(); 
         // Input 
         jobData.DocumentId = inputDocumentId; 
         jobData.Cache = cache; 
 
         // Output, upload to the same cache as a new document 
         var uploadDocumentOptions = new UploadDocumentOptions(); 
         uploadDocumentOptions.Cache = cache; 
         jobData.UploadDocumentOptions = uploadDocumentOptions; 
 
         // Options 
         jobData.DocumentFormat = DocumentFormat.Pdf; 
 
         // Run 
         Console.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 file 
            using (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 up 
   var 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); 
   } 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.URI; 
import java.util.concurrent.Executors; 
import java.util.logging.ConsoleHandler; 
import java.util.logging.Handler; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.annotations.rendering.AnnJavaRenderingEngine; 
import leadtools.caching.FileCache; 
import leadtools.codecs.*; 
import leadtools.document.DocumentFactory; 
import leadtools.document.DownloadDocumentOptions; 
import leadtools.document.LEADDocument; 
import leadtools.document.LoadDocumentOptions; 
import leadtools.document.LoadFromCacheOptions; 
import leadtools.document.UploadDocumentOptions; 
import leadtools.document.converter.DocumentConverter; 
import leadtools.document.converter.DocumentConverterEmptyPageMode; 
import leadtools.document.converter.DocumentConverterJob; 
import leadtools.document.converter.DocumentConverterJobData; 
import leadtools.document.converter.DocumentConverterJobError; 
import leadtools.document.converter.DocumentConverterJobErrorMode; 
import leadtools.document.converter.DocumentConverterJobStatus; 
import leadtools.document.converter.DocumentConverterJobs; 
import leadtools.document.writer.DocumentFormat; 
import leadtools.document.writer.DocumentWriter; 
import leadtools.ocr.OcrEngine; 
import leadtools.ocr.OcrEngineManager; 
import leadtools.ocr.OcrEngineType; 
 
 
public void uploadToCacheExample() { 
   // We will be converting this TIFF file to PDF 
   String imageUrl = "https://demo.leadtools.com/images/tiff/ocr.tif"; 
   // Download the final document to this file 
   String outputFile = "C:\\Temp\\Cache\\output.pdf"; 
   String inputDocumentId = null; 
   URI outputDocumentUrl = null; 
 
   // Setup the cache 
   FileCache cache = new FileCache(); 
   cache.setCacheDirectory("C:\\Temp\\Cache"); 
 
   // Load the document and save it to the cache 
   LoadDocumentOptions loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.setCache(cache); 
   System.out.println("Saving input document into the cache"); 
   try { 
      LEADDocument document = DocumentFactory.loadFromUri(new URI(imageUrl), loadDocumentOptions); 
      // Store the document ID to use it later 
      inputDocumentId = document.getDocumentId(); 
      // Make sure the document persist on the cache after we dispose it 
      document.setAutoSaveToCache(false); 
      document.setAutoDeleteFromCache(false); 
      document.saveToCache(); 
   } catch (Exception e) { 
      e.printStackTrace(); 
   } 
 
   // Convert the document to PDF and automatically upload it 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
   ocrEngine.startup(null, null, null, "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"); 
   DocumentConverter documentConverter = new DocumentConverter(); 
   documentConverter.setOcrEngineInstance(ocrEngine, false); 
   DocumentConverterJobData jobData = new DocumentConverterJobData(); 
   // Input 
   jobData.setDocumentId(inputDocumentId); 
   jobData.setCache(cache); 
 
   // Output, upload to the same cache as a new document 
   UploadDocumentOptions uploadDocumentOptions = new UploadDocumentOptions(); 
   uploadDocumentOptions.setCache(cache); 
   jobData.setUploadDocumentOptions(uploadDocumentOptions); 
 
   // Options 
   jobData.setDocumentFormat(DocumentFormat.PDF); 
 
   // Run 
   System.out.println(String.format("Converting %s and uploading%n", inputDocumentId)); 
   DocumentConverterJob job = documentConverter.getJobs().createJob(jobData); 
   documentConverter.getJobs().runJob(job); 
   assertTrue(job.getStatus() == DocumentConverterJobStatus.SUCCESS); 
   System.out.println(job.getStatus()); 
   if (job.getStatus() != DocumentConverterJobStatus.ABORTED) { 
      System.out.println("Downloading " + job.getUploadDocumentUri()); 
      // Download it from the cache to the output file 
      try { 
         FileOutputStream fos = new FileOutputStream(new File(outputFile)); 
         ILeadStream outStream = new LeadStream(fos, false); 
         DownloadDocumentOptions downloadDocumentOptions = new DownloadDocumentOptions(); 
         downloadDocumentOptions.setCache(cache); 
         downloadDocumentOptions.setDocumentId(job.getUploadDocumentUri().toString()); 
         downloadDocumentOptions.setOffset(0); 
         downloadDocumentOptions.setLength(-1); 
         downloadDocumentOptions.setStream(outStream); 
         DocumentFactory.downloadDocument(downloadDocumentOptions); 
      } catch (Exception e) { 
         e.printStackTrace(); 
      } 
      outputDocumentUrl = job.getUploadDocumentUri(); 
   } 
 
   // Clean up 
   LoadFromCacheOptions deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.setCache(cache); 
   if (inputDocumentId != null) { 
      deleteFromCacheOptions.setDocumentId(inputDocumentId); 
      DocumentFactory.deleteFromCache(deleteFromCacheOptions); 
   } 
   if (outputDocumentUrl != null) { 
      deleteFromCacheOptions.setDocumentId(outputDocumentUrl.toString()); 
      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.Converter Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.