create Method


Creates a new empty virtual document.


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



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.


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

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.


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 = [ 
   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 
          .fail(function (jqXHR, statusText, errorThrown) { 
             showServiceError(jqXHR, statusText, errorThrown); 
          .always(function () { 
             if (processedCount >= childDocCount) { 
                // All children loaded, if we did not have an error continue with the example 
                if (loadedCount == processedCount) { 
             else { 
function createDocument(childDocs) { 
   // Create a new document 
   var createOptions = new lt.Documents.CreateDocumentOptions(); 
   var doc = lt.Documents.DocumentFactory.create(createOptions); = "Virtual"; 
   // Should have 0 pages and documents 
   // Add page 1 and 2 from the first child document (PDF) 
   var childDoc = childDocs[0]; 
   // 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); 
   // Add page 3 and 4 from the second child document (TIFF) 
   childDoc = childDocs[1]; 
   // Should have 5 pages and 2 documents (the PDF and the TIFF) 
   console.log("Pages added"); 
   // Save the ID so we can load it 
   var documentId = doc.documentId; 
   // Now save, the parent document into the cache 
       .done(function () { 
          // Tell the document to dispose all children 
          doc.autoDisposeDocuments = true; 
          // And dispose it 
          // Now, re-load this document from the cache 
              .done(function (doc) { 
                 // Should have 5 pages and 2 documents (the PDF and the TIFF) 
                 console.log("Document loaded from cache"); 
                 // Delete first page 
                 // 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"); 
                 // Delete this document from the cache 
                 // Note: This does not delete the children 
              .fail(function (jqXHR, statusText, errorThrown) { 
                 showServiceError(jqXHR, statusText, errorThrown); 
       .fail(function (jqXHR, statusText, errorThrown) { 
          showServiceError(jqXHR, statusText, errorThrown); 


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