←Select platform

Create(CreateDocumentOptions) Method

Summary

Creates a new empty virtual document.

Syntax

C#
VB
Java
C++
public static Document Create( 
   CreateDocumentOptions options 
) 
Public Shared Function Create( 
   ByVal options As CreateDocumentOptions 
) As Document 
public:  
   static Document^ Create( 
      CreateDocumentOptions^ options 
   ) 
public static Document create(CreateDocumentOptions options) 

Parameters

options

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

Return Value

The newly created document.

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
Cache and UseCache Used to determine if the newly created document will be saved into the cache later.
CachePolicy If caching is used: Copied to the newly created document and is used to determine when the document and its item are purged from the cache.
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. Use one of the MIME types constants defined in the Constants class. In the case of virtual documents, this value can be left as null.
Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Documents; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
using Leadtools.Barcode; 
 
public static void DocumentFactoryCreateExample() 
{ 
   var cache = GetCache(); 
 
   // Create a new document 
   var createOptions = new CreateDocumentOptions(); 
   createOptions.Cache = cache; 
 
   string documentId = null; 
 
   using (Document document = DocumentFactory.Create(createOptions)) 
   { 
      document.Name = "Virtual"; 
 
      // Should have 0 pages and documents 
      System.Diagnostics.Debug.Assert(document.Pages.Count == 0); 
      System.Diagnostics.Debug.Assert(document.Documents.Count == 0); 
 
      // Add page 1 and 2 from a PDF file 
      LoadDocumentOptions loadOptions = new LoadDocumentOptions(); 
      loadOptions.Cache = cache; 
      Document childDocument = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Leadtools.pdf"), loadOptions); 
      // Do not dispose the child documents, but save it into the cache 
      // This is optional and is done in this example since we will try to re-load the parent document 
      // from the cache - and the child documents should be in the cache as well 
      childDocument.SaveToCache(); 
      // Now add the pages 
      document.Pages.Add(childDocument.Pages[0]); 
      document.Pages.Add(childDocument.Pages[1]); 
 
      // Add an empty page 
      var documentPage = document.Pages.CreatePage(LeadSizeD.Create(Document.UnitsPerInch * 8.5, Document.UnitsPerInch * 11), 300); 
      document.Pages.Add(documentPage); 
 
      // Add page 3 and 4 from a TIF file 
      childDocument = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Ocr.tif"), loadOptions); 
      // Also save it into the cache 
      childDocument.SaveToCache(); 
      // Now add the pages 
      document.Pages.Add(childDocument.Pages[2]); 
      document.Pages.Add(childDocument.Pages[3]); 
 
      // Should have 5 pages and 2 documents (the PDF and the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count == 5); 
      System.Diagnostics.Debug.Assert(document.Documents.Count == 2); 
 
      // Tell the parent document to dispose any child documents when the parent is disposed 
      document.AutoDisposeDocuments = true; 
 
      // Show the info of this document, should say 5 pages 
      Console.WriteLine("Original document information"); 
      PrintOutDocumentInfo(document); 
 
      // Now save, the parent document into the cache 
      document.SaveToCache(); 
 
      // And tell all documents to not delete themselves from the cache 
      document.AutoDeleteFromCache = false; 
 
      // Save the ID so we can load it 
      documentId = document.DocumentId; 
   } 
 
   // Now, load the document from the cache 
   using (Document document = DocumentFactory.LoadFromCache(cache, documentId)) 
   { 
      // Should have 5 pages and 2 documents (the PDF and the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count == 5); 
      System.Diagnostics.Debug.Assert(document.Documents.Count == 2); 
 
      // Show the info of this document, should still say 5 pages 
      Console.WriteLine("Loaded from cache information"); 
      PrintOutDocumentInfo(document); 
 
      // Delete first page 
      document.Pages.RemoveAt(0); 
      // Delete the last page 
      document.Pages.RemoveAt(document.Pages.Count - 1); 
 
      // Should have 3 pages and 2 documents (the PDF and the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count == 3); 
      System.Diagnostics.Debug.Assert(document.Documents.Count == 2); 
 
      Console.WriteLine("After removing the first 2 pages"); 
      PrintOutDocumentInfo(document); 
 
      // Delete this document and all its children from the cache when we are disposed 
      document.AutoDeleteFromCache = true; 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Svg 
Imports Leadtools.Documents 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Barcode 
Imports Leadtools.Forms.Ocr 
Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
'Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
 
Public Sub DocumentFactoryCreateExample() 
   Dim cache As ObjectCache = GetCache() 
 
   ' Create a New document 
   Dim createOptions As New CreateDocumentOptions() 
   createOptions.Cache = cache 
 
   Dim documentId As String = Nothing 
 
   Using document As Document = DocumentFactory.Create(createOptions) 
      document.Name = "Virtual" 
 
      ' Should have 0 pages And documents 
      System.Diagnostics.Debug.Assert(document.Pages.Count = 0) 
      System.Diagnostics.Debug.Assert(document.Documents.Count = 0) 
 
      ' Add page 1 And 2 from a PDF file 
      Dim loadOptions As New LoadDocumentOptions() 
      loadOptions.Cache = cache 
      Dim childDocument As Document = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Leadtools.pdf"), loadOptions) 
      ' Do Not dispose the child documents, but save it into the cache 
      ' This Is optional And Is done in this example since we will try to re-load the parent document 
      ' from the cache - And the child documents should be in the cache as well 
      childDocument.SaveToCache() 
      ' Now add the pages 
      document.Pages.Add(childDocument.Pages(0)) 
      document.Pages.Add(childDocument.Pages(1)) 
 
      ' Add an empty page 
      Dim documentPage As Leadtools.Documents.DocumentPage = document.Pages.CreatePage(LeadSizeD.Create(document.UnitsPerInch * 8.5, document.UnitsPerInch * 11), 300) 
      document.Pages.Add(documentPage) 
 
      ' Add page 3 And 4 from a TIF file 
      childDocument = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Ocr.tif"), loadOptions) 
      ' Also save it into the cache 
      childDocument.SaveToCache() 
      ' Now add the pages 
      document.Pages.Add(childDocument.Pages(2)) 
      document.Pages.Add(childDocument.Pages(3)) 
 
      ' Should have 5 pages And 2 documents (the PDF And the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count = 5) 
      System.Diagnostics.Debug.Assert(document.Documents.Count = 2) 
 
      ' Tell the parent document to dispose any child documents when the parent Is disposed 
      document.AutoDisposeDocuments = True 
 
      ' Show the info of this document, should say 5 pages 
      Console.WriteLine("Original document information") 
      PrintOutDocumentInfo(document) 
 
      ' Now save, the parent document into the cache 
      document.SaveToCache() 
 
      ' And tell all documents to Not delete themselves from the cache 
      document.AutoDeleteFromCache = False 
 
      ' Save the ID so we can load it 
      documentId = document.DocumentId 
   End Using 
 
   ' Now, load the document from the cache 
   Using document As Document = DocumentFactory.LoadFromCache(cache, documentId) 
      ' Should have 5 pages And 2 documents (the PDF And the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count = 5) 
      System.Diagnostics.Debug.Assert(document.Documents.Count = 2) 
 
      ' Show the info of this document, should still say 5 pages 
      Console.WriteLine("Loaded from cache information") 
      PrintOutDocumentInfo(document) 
 
      ' Delete first page 
      document.Pages.RemoveAt(0) 
      ' Delete the last page 
      document.Pages.RemoveAt(document.Pages.Count - 1) 
 
      ' Should have 3 pages And 2 documents (the PDF And the TIF) 
      System.Diagnostics.Debug.Assert(document.Pages.Count = 3) 
      System.Diagnostics.Debug.Assert(document.Documents.Count = 2) 
 
      Console.WriteLine("After removing the first 2 pages") 
      PrintOutDocumentInfo(document) 
 
      ' Delete this document And all its children from the cache when we are disposed 
      document.AutoDeleteFromCache = True 
   End Using 
End Sub 

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