Uploading Using the Document Library

The Document library supports uploading documents from the user drive to the cache system. This support is helpful when the cache is hosted on a separate machine not accessible to the user (for example, when the Documents class is hosted in a web service with a JavaScript or rich client application, such as the HTML5/JavaScript version of the LEADTOOLS Document Viewer using the LEADTOOLS Document Web Service).

There are two ways to upload a document to the cache system:

In both ways of uploading, the URI can be used with LoadFromUri to download the LEADDocument data.

If the total length of the data being uploaded is available at this time, setting the value of UploadDocumentOptions.DocumentDataLength can greatly help the service optimize the loading operations.

When uploading is finished, EndUpload must be called to inform the factory that the uploading process has finished.

Refer to UploadFile, UploadFileDocument, UploadDocumentBlob or UploadDocument for examples.

Enable Streaming

During the upload process, the DocumentFactory will save each chunk into the cache during UploadDocument. Therefore, the latest document data is available to all users of the system. If the system encounters an error and the process restarts, the upload operation can be restarted and uploading continues. This also ensures minimum amount of memory is needed when uploading large documents (only chunk size is need at any time). This the default behavior when UploadDocumentOptions.EnableStreaming is false (the default value).up

If EnableStreaming is set to true, then the DocumentFactory will not save the chunk data into the cache during UploadDocument. Instead, it will create an internal stream in memory and append the chunks into it as they arrive. When EndUpload is called, the factory will then store all the data at once from the stream into the cache. This may speed up uploading of document on the expense of more memory being used (the whole document data will be in memory) and uploading operations cannot be restarted if the system encounters an error and the process restarts. Therefore, it is recommended not to set EnableStreaming to true unless the system is designed for single process or single user operations.

Post Upload Operations

Post upload operations can be perform on a document after it has been uploaded to the cache and before it is first loaded. These operations and their optional values can be set in the UploadDocumentOptions.PostUploadOperations dictionary.

The operations are performed when EndUpload is called.

The current version of LEADTOOLS contains support for the following post upload operations:

Auto-Linearize PDF

Linearized PDF are documents that are optimized for fast web viewing. The LEADTOOLS JavaScript Document Viewer when using client-side rendering can take advantage of linearized PDF to start viewing the PDF file before all its content is downloaded.

Uploaded PDF files can be checked for linearization and converted upon upload using the following:

// Automatically linearize (optimize for fast web viewing) PDF files that are greater than 1 MBytes in size. 
var pdfData = ...; // PDF data to upload as a byte array 
var pdfPassword = null; // If the PDF is encrypted, set its password here 
var uploadDocumentOptions = new lt.Document.UploadDocumentOptions(); 
var minimumLengthInBytes = 1024 * 1024; 
uploadDocumentOptions.postUploadOperations[lt.Document.LEADDocument.postUpload_LinearizePdfMinimumLength] = minimumLengthInBytes.toString(); 
// The factory will not perform this operation unless we set the correct mime type: 
uploadDocumentOptions.mimeType = "application/pdf"; 
uploadDocumentOptions.password = pdfPassword; 
// Now upload 
var uploadDocumentUri; 
lt.Document.DocumentFactory.beginUploadDocument(uploadDocumentOptions) 
   .done(function (documentUri) { 
      uploadDocumentUri = documentUri; 
      lt.Document.DocumentFactory.uploadDocument(documentUri, pdfData, 0, pdfData.length); 
   }) 
   .done(function () { 
      lt.Document.DocumentFactory.endUpload(uploadDocumentUri); 
   }); 

The factory will perform the following actions on endUpload:

If the PDF is encrypted, a password is required to linearize it. The password can be passed in UploadDocumentOptions.Password as shown above.

The metadata of LEADDocument can be examined to determine if this is a PDF document with linearized data using the following code:

lt.Document.DocumentFactory.loadFromCache(documentId) 
   .done(function (leadDocument) { 
      var isLinearized = false; 
      // Check if the metadata contains the key 
      var isLinearizedValue = leadDocument.metadata[lt.Document.LEADDocument.metadataKey_IsLinearized]; 
      if (isLinearizedValue) { 
         // Yes 
         isLinearized = (isLinearizedValue === "true"); 
      } 
      if (isLinearized) { 
         // Perform additional actions 
      } 
   }); 

See Also

Document Viewer Application

Document Library Features

Loading Documents Using LEADTOOLS Document Library

Creating Documents with LEADTOOLS Document Library

Document Toolkit and Caching

Document Library Coordinate System

Loading Encrypted Files Using the Document Library

Parsing Text with the Document Library

Barcode processing with the Document Library

Using jQuery Promises in the Document Library

Loading Images in the Document Library

Document Page Transformation

Using LEADTOOLS Document Viewer

Status Document Job Converter

Document View and Convert Redaction

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

LEADTOOLS HTML5 JavaScript
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.