Creates a new empty virtual document.
public static LEADDocument Create(CreateDocumentOptions options)
Public Shared Function Create(ByVal options As CreateDocumentOptions) As LEADDocument
public:static LEADDocument^ Create(CreateDocumentOptions^ options)
public static Document create(CreateDocumentOptions options)
options
Options to use when creating the document. Cannot be null.
The newly created document.
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 LEADDocument 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. |
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Document;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;using Leadtools.Barcode;using Leadtools.Document.Converter;public void DocumentFactoryCreateExample(){var cache = GetCache();// Create a new documentvar createOptions = new CreateDocumentOptions();createOptions.Cache = cache;string documentId = null;using (LEADDocument document = DocumentFactory.Create(createOptions)){document.Name = "Virtual";// Should have 0 pages and documentsSystem.Diagnostics.Debug.Assert(document.Pages.Count == 0);System.Diagnostics.Debug.Assert(document.Documents.Count == 0);// Add page 1 and 2 from a PDF fileLoadDocumentOptions loadOptions = new LoadDocumentOptions();loadOptions.Cache = cache;LEADDocument childDocument = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "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 wellchildDocument.SaveToCache();// Now add the pagesdocument.Pages.Add(childDocument.Pages[0]);document.Pages.Add(childDocument.Pages[1]);// Add an empty pagevar documentPage = document.Pages.CreatePage(LeadSizeD.Create(LEADDocument.UnitsPerInch * 8.5, LEADDocument.UnitsPerInch * 11), 300);document.Pages.Add(documentPage);// Add page 3 and 4 from a TIF filechildDocument = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "ocr1.tif"), loadOptions);// Also save it into the cachechildDocument.SaveToCache();// Now add the pagesdocument.Pages.Add(childDocument.Pages[0]);document.Pages.Add(childDocument.Pages[0]);// 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 disposeddocument.AutoDisposeDocuments = true;// Show the info of this document, should say 5 pagesConsole.WriteLine("Original document information");PrintOutDocumentInfo(document);// Now save, the parent document into the cachedocument.SaveToCache();// And tell all documents to not delete themselves from the cachedocument.AutoDeleteFromCache = false;// Save the ID so we can load itdocumentId = document.DocumentId;}// Now, load the document from the cachevar loadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = documentId;using (LEADDocument document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// 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 pagesConsole.WriteLine("Loaded from cache information");PrintOutDocumentInfo(document);// Delete first pagedocument.Pages.RemoveAt(0);// Delete the last pagedocument.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 disposeddocument.AutoDeleteFromCache = true;}}public void PrintOutDocumentInfo(LEADDocument document){Console.WriteLine("General");Console.WriteLine(" DocumentId:" + document.DocumentId);if (document.Uri != null)Console.WriteLine(" Uri:" + document.Uri);Console.WriteLine(" Name:" + document.Name);Console.WriteLine(" CacheStatus:" + document.CacheStatus);Console.WriteLine(" LastCacheSyncTime:" + document.LastCacheSyncTime);Console.WriteLine(" IsReadOnly:" + document.IsReadOnly);Console.WriteLine(" IsLocal:" + document.IsLocal);Console.WriteLine(" MimeType:" + document.MimeType);Console.WriteLine(" IsEncrypted:" + document.IsEncrypted);Console.WriteLine(" IsDecrypted:" + document.IsDecrypted);Console.WriteLine(" UserData:" + document.UserData);Console.WriteLine("Cache");Console.WriteLine(" HasCache:" + document.HasCache);Console.WriteLine(" AutoDeleteFromCache:" + document.AutoDeleteFromCache);Console.WriteLine("Metadata");foreach (var item in document.Metadata)Console.WriteLine(" {0} {1}", item.Key, item.Value);Console.WriteLine("Documents");Console.WriteLine(" Count:" + document.Documents.Count);foreach (var childDocument in document.Documents){Console.WriteLine(" Name:" + childDocument.Name);}Console.WriteLine("Pages");Console.WriteLine(" Count:" + document.Pages.Count);for (var pageNumber = 1; pageNumber <= document.Pages.Count; pageNumber++){var page = document.Pages[pageNumber - 1];Console.WriteLine(" PageNumber:" + pageNumber);Console.WriteLine(" OriginalPageNumber:" + page.OriginalPageNumber);Console.WriteLine(" OriginalDocumentName:" + page.Document.Name);Console.WriteLine(" Size:{0}", page.Size);}Console.WriteLine("--------");}public ObjectCache GetCache(){// Create a LEADTOOLS FileCache objectvar cacheDir = Path.Combine(LEAD_VARS.ImagesDir, "cache");if (Directory.Exists(cacheDir))Directory.Delete(cacheDir, true);Directory.CreateDirectory(cacheDir);var cache = new FileCache();cache.CacheDirectory = cacheDir;return cache;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.BarcodeImports Leadtools.OcrImports LeadtoolsDocumentExamples.LeadtoolsExamples.CommonImports Leadtools.Document.ConverterPublic Sub DocumentFactoryCreateExample()Dim cache As ObjectCache = GetCache()' Create a New documentDim createOptions As New CreateDocumentOptions()createOptions.Cache = cacheDim documentId As String = NothingUsing document As LEADDocument = DocumentFactory.Create(createOptions)document.Name = "Virtual"' Should have 0 pages And documentsSystem.Diagnostics.Debug.Assert(document.Pages.Count = 0)System.Diagnostics.Debug.Assert(document.Documents.Count = 0)' Add page 1 And 2 from a PDF fileDim loadOptions As New LoadDocumentOptions()loadOptions.Cache = cacheDim childDocument As LEADDocument = 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 wellchildDocument.SaveToCache()' Now add the pagesdocument.Pages.Add(childDocument.Pages(0))document.Pages.Add(childDocument.Pages(1))' Add an empty pageDim documentPage As Leadtools.Document.DocumentPage = document.Pages.CreatePage(LeadSizeD.Create(LEADDocument.UnitsPerInch * 8.5, LEADDocument.UnitsPerInch * 11), 300)document.Pages.Add(documentPage)' Add page 3 And 4 from a TIF filechildDocument = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Ocr.tif"), loadOptions)' Also save it into the cachechildDocument.SaveToCache()' Now add the pagesdocument.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 disposeddocument.AutoDisposeDocuments = True' Show the info of this document, should say 5 pagesConsole.WriteLine("Original document information")PrintOutDocumentInfo(document)' Now save, the parent document into the cachedocument.SaveToCache()' And tell all documents to Not delete themselves from the cachedocument.AutoDeleteFromCache = False' Save the ID so we can load itdocumentId = document.DocumentIdEnd Using' Now, load the document from the cacheDim loadFromCacheOptions As New LoadFromCacheOptionsloadFromCacheOptions.Cache = cacheloadFromCacheOptions.DocumentId = documentIdUsing document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)' 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 pagesConsole.WriteLine("Loaded from cache information")PrintOutDocumentInfo(document)' Delete first pagedocument.Pages.RemoveAt(0)' Delete the last pagedocument.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 disposeddocument.AutoDeleteFromCache = TrueEnd UsingEnd SubPublic Shared Sub PrintOutDocumentInfo(ByVal document As LEADDocument)Console.WriteLine("General")Console.WriteLine(" DocumentId:" + document.DocumentId)If Not IsNothing(document.Uri) ThenConsole.WriteLine(" Uri:" + document.Uri.ToString())ElseConsole.WriteLine(" Name:" + document.Name)End IfConsole.WriteLine(" CacheStatus:" + document.CacheStatus.ToString())Console.WriteLine(" LastCacheSyncTime:" + document.LastCacheSyncTime.ToString())Console.WriteLine(" IsReadOnly:" + document.IsReadOnly.ToString())Console.WriteLine(" IsLocal:" + document.IsLocal.ToString())Console.WriteLine(" MimeType:" + document.MimeType)Console.WriteLine(" IsEncrypted:" + document.IsEncrypted.ToString())Console.WriteLine(" IsDecrypted:" + document.IsDecrypted.ToString())If Not IsNothing(document.UserData) ThenConsole.WriteLine(" UserData:" + document.UserData.ToString())End IfConsole.WriteLine("Cache")Console.WriteLine(" HasCache:" + document.HasCache.ToString())Console.WriteLine(" AutoDeleteFromCache:" + document.AutoDeleteFromCache.ToString())Console.WriteLine("Metadata")For Each item As KeyValuePair(Of String, String) In document.MetadataConsole.WriteLine(" {0} {1}", item.Key, item.Value)NextConsole.WriteLine("Documents")Console.WriteLine(" Count:" + document.Documents.Count.ToString())For Each childDocument As LEADDocument In document.DocumentsConsole.WriteLine(" Name:" + childDocument.Name)NextConsole.WriteLine("Pages")Console.WriteLine(" Count:" + document.Pages.Count.ToString())For pageNumber As Integer = 1 To document.Pages.CountDim page As Leadtools.Document.DocumentPage = document.Pages(pageNumber - 1)Console.WriteLine(" PageNumber:" + pageNumber.ToString())Console.WriteLine(" OriginalPageNumber:" + page.OriginalPageNumber.ToString())Console.WriteLine(" OriginalDocumentName:" + page.Document.Name)Console.WriteLine(" Size:{0}", page.Size.ToString())NextConsole.WriteLine("--------")End SubPublic Shared Function GetCache() As ObjectCache' Create a LEADTOOLS FileCache objectDim cacheDir As String = Path.Combine(ImagesPath.Path, "cache")If Directory.Exists(cacheDir) ThenDirectory.Delete(cacheDir, True)End IfDirectory.CreateDirectory(cacheDir)Dim cache As New FileCache()cache.CacheDirectory = cacheDirReturn cacheEnd Function
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
