Loading Documents Using LEADTOOLS Document Library


The Document library supports loading by creating a Document object from data that resides in a disk file or a remote URL or data that was previously uploaded to the cache system.

This topic discusses the loading the information associated with representing a document as a Document object. For a discussion of loading individual page images or thumbnails for a DocumentPage, see Image Loading.

Loading from Remote URL

To load a Document object from a remote URL call LoadFromUri, passing the URL pointing to the remote location of the document file and an instance (which can be null) of LoadDocumentOptions. Refer to LoadFromUri for an example.

Following is an explanation on how this method works.

  1. If the uri passed to LoadFromUri has the special LEAD cache scheme (detected using IsUploadDocumentUri), then the factory assumes this is the URI to a document previously uploaded to the cache using LoadFromUri and steps below are not performed and no data is downloaded. The data is already in the cache and the factory skips to step 4 below.

  2. If the value of AnnotationsUri is not null, then it will be treated as a remote URL and the data is downloaded by the factory in the same manner used for the document file as explained below.

  3. The factory will download the document dta from uri into the cache system.

  4. Similarly, if AnnotationsUri is not null, it will be downloaded to the cache system.

  5. The factory will obtain information on the file format on the downloaded or temporary file. If this fails (invalid file format or the required LEADTOOLS file format assembly is not found), then the cache data is deleted and an exception is thrown.

  6. A Document object is created and the following members are initialized:

    Member Value

    A unique identifier created for this document that can be used if the document is saved to the cache.


    Same uri passed to LoadFromUri.

    IsReadOnly true.
    CacheUri If the document was downloaded to the cache and if the cache system has virtual directory capabilities, then this property will contain a URI to the original document data (PDF, TIFF, DOCX, etc.). Otherwise, is null.

    The MIME type of the document file format set during load.

    LastCacheSyncTime Random old date since the document has not been saved to the cache yet.
    CacheStatus DocumentCacheStatus.NotSynced since the document has not been saved to the cache yet.

    false unless the document is encrypted. In this case most of the document properties cannot be used before the document is decrypted. Refer to Loading Encrypted Files Using the Document Library for more information.




    true or false based on the MIME type of the document.


    Ready to be used.


    Ready to be used.


    Ready to be used.


    Ready to be used.


    Ready to be used.

    Documents Empty collection since this is not a virtual document.
    HasDocuments false.
    AutoDisposeDocuments false.

    Ready to be used.

  7. LoadFromUri returns with this Document object ready to be used.

  8. Document parses data from the downloaded data, therefore the original URL is never used again and the data it points to can be deleted right away if necessary.

Refer to LoadFromUri for an example.

LoadFromFile can be used to load a document stored in a JavaScript File object. The factory will first upload the document data to service before calling LoadFromUri on the result URI.

Loading from Cache

As stated above, a valid uri to a Document in the cache scheme can be retrieved from LoadFromUri without issue. However, LoadFromCache also exists as a subset of LoadFromUri's functionality for instances in which a Document has already been loaded once but must be loaded again. LoadFromCache does not take a LoadDocumentOptions object.

LoadFromCache uses the DocumentId property to download the Document data, so that value may be stored instead of the Uri when holding on to cache items for later.

Refer to LoadFromUri for an example.

Document User Tokens

Each LEADDocument can optionally be associated with a user token to restrict usage. For instance, when a document is first loaded from a URI into the cache using DocumentFactory.loadFromUri, and adding the user-token header to the request and setting its value to the desired token. If this value is set and is not null, it will be used as the user token associated with this document. Subsequent calls to DocumentFactory.loadFromCache will fail if the value of user-token header does not match.

Similarly, a user token can be associated when a document is created from scratch using DocumentFactory.create and when a document is uploaded to the cache using (DocumentFactory.beginUpload or DocumentFactory.beginUploadDocument. Attempts to then load these documents with DocumentFactory.loadFromUri or DocumentFactory.loadFromCache will fail if the same user token is not passed accordingly. The same behavior also occurs during DocumentFactory.deleteFromCache, DocumentFactory.downloadDocumentData or DocumentFactory.downloadDocumentData

When using DocumentFactory.checkCacheInfo to obtain information on a document in the cache, the value of CacheInfo.hasUserToken will indicate if the document in the cache contains a user token and cannot be loaded or deleted if the correct user token is not used.

Refer to the Document Viewer Demo for an example on how to use a user token.

See Also

Document Library Features

Document Viewer Application

Creating Documents with LEADTOOLS Document Library

Document Toolkit and Caching

Uploading Using the Document Library

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 20.0.2019.10.14
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.