create Method

Summary

Creates a new empty virtual document.

Syntax

JavaScript Syntax
create = function(options) 
TypeScript Syntax
static create(options: CreateDocumentOptions): JQueryPromise<Document>; 

Parameters

options

Options to use when creating the document. Cannot be null.

Return Value

A Promise object that may resolve successfully to a Document object, or fail if the Document cannot be returned because it does not exist with that documentId.

Remarks

Creates a new empty virtual document ready to be filled with pages from other documents.

This method will add items with the key "Created", "Accessed" and "Modified" to Metadata with values equal to the current date and time. The newly created Document object will have an empty list of Pages. It can then be populated by the user.

The member of options are used as follows:

Member Description
DocumentId

The ID to be used with the loaded document. When this value null (the default), then the document factory will create a new unique ID using a GUID generator. If the value is not null, then it is assumed to be a user-defined ID and used as is. In either case, the value is set in the Document.DocumentId property of the newly created document.

User-defined IDs can be used when the system already have unique ID's associated with the documents to be viewer. The document factory will not check nor guarantee the uniqueness of these IDs.
MimeType Copied as is into the newly created document MimeType member. This value can be null but it is recommend you set it to the MIME type of the document since it will be used when saving the document. In the case of virtual documents, this value can be left as null.

Created documents can be saved into the cache using SaveToCache.

Example

This examples will show how to compose a virtual document from subset of PDF and a TIFF document pages.

JavaScript Example
function documentFactoryCreateExample() { 
   // Load a couple of documents that will be used as the source 
   // PDF and TIFF 
   var urls = [ 
       "http://localhost/images/documents/leadtools.pdf", 
       "http://localhost/images/ocr/ocr.tif" 
   ]; 
   var childDocs = []; 
   var childDocCount = urls.length; 
   var processedCount = 0; 
   var loadedCount = 0; 
   var loadDocument = function () { 
      // Load this one 
      var index = processedCount; 
      var loadOptions = new lt.Documents.LoadDocumentOptions(); 
      console.log("Loading " + urls[index]); 
      lt.Documents.DocumentFactory.loadFromUri(urls[index], loadOptions) 
          .done(function (childDoc) { 
             // Finished, save the document and load next 
             loadedCount++; 
             childDocs.push(childDoc); 
          }) 
          .fail(function (jqXHR, statusText, errorThrown) { 
             showServiceError(jqXHR, statusText, errorThrown); 
          }) 
          .always(function () { 
             processedCount++; 
             if (processedCount >= childDocCount) { 
                // All children loaded, if we did not have an error continue with the example 
                if (loadedCount == processedCount) { 
                   createDocument(childDocs); 
                } 
             } 
             else { 
                loadDocument(); 
             } 
          }); 
   }; 
   loadDocument(); 
} 
 
function createDocument(childDocs) { 
   // Create a new document 
   var createOptions = new lt.Documents.CreateDocumentOptions(); 
   var doc = lt.Documents.DocumentFactory.create(createOptions); 
   doc.name = "Virtual"; 
   // Should have 0 pages and documents 
   console.log("Created"); 
   showDocumentInfo(doc); 
   // Add page 1 and 2 from the first child document (PDF) 
   var childDoc = childDocs[0]; 
   doc.pages.add(childDoc.pages.item(0)); 
   doc.pages.add(childDoc.pages.item(1)); 
   // Add an empty page (8.5 by 11 inches at 300 DPI) 
   var docPage = doc.pages.createPage(lt.LeadSizeD.create(lt.Documents.Document.unitsPerInch * 8.5, lt.Documents.Document.unitsPerInch * 11), 300); 
   doc.pages.add(docPage); 
   // Add page 3 and 4 from the second child document (TIFF) 
   childDoc = childDocs[1]; 
   doc.pages.add(childDoc.pages.item(2)); 
   doc.pages.add(childDoc.pages.item(3)); 
   // Should have 5 pages and 2 documents (the PDF and the TIFF) 
   console.log("Pages added"); 
   showDocumentInfo(doc); 
   // Save the ID so we can load it 
   var documentId = doc.documentId; 
   // Now save, the parent document into the cache 
   lt.Documents.DocumentFactory.saveToCache(doc) 
       .done(function () { 
          // Tell the document to dispose all children 
          doc.autoDisposeDocuments = true; 
          // And dispose it 
          doc.dispose(); 
          // Now, re-load this document from the cache 
          lt.Documents.DocumentFactory.loadFromCache(documentId) 
              .done(function (doc) { 
                 // Should have 5 pages and 2 documents (the PDF and the TIFF) 
                 console.log("Document loaded from cache"); 
                 showDocumentInfo(doc); 
                 // Delete first page 
                 doc.pages.removeAt(0); 
                 // Delete the last page 
                 doc.pages.removeAt(doc.pages.count - 1); 
                 // Should have 3 pages and 2 documents (the PDF and the TIF) 
                 console.log("After removing first and last pages"); 
                 showDocumentInfo(doc); 
                 // Delete this document from the cache 
                 // Note: This does not delete the children 
                 lt.Documents.DocumentFactory.deleteFromCache(documentId); 
              }) 
              .fail(function (jqXHR, statusText, errorThrown) { 
                 showServiceError(jqXHR, statusText, errorThrown); 
              }); 
       }) 
       .fail(function (jqXHR, statusText, errorThrown) { 
          showServiceError(jqXHR, statusText, errorThrown); 
       }); 
} 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly