Represents a collection of LEADDocument objects.
[CollectionDataContractAttribute()]public class DocumentDocuments : LeadCollection<LEADDocument>
DocumentDocuments manages the children of the document. It can be accessed through the Documents property of LEADDocument.
DocumentDocuments derives from LeadCollection<T> and this can implement [System.Collections.ObjectModel.Collection1](https://msdn.microsoft.com/en-us/library/System.Collections.ObjectModel.Collection1.aspx). You can use any of the collection methods
to iterate through the documents. This collection is read-only however and you cannot add, remove or change the items. Instead, use Pages to add or remove
pages that belong to a document separate from this one. The LEADDocument.Documents collection will automatically get updated to reflect what child
documents are currently held in the document.
Here is an example that shows what happens to LEADDocument.Documents when pages are added and removed:
When document (virtualDocument is created, LEADDocument.Documents is an empty collection.
The user creates a new empty page using CreatePage of virtualDocument and then adds it to the
LEADDocument.Pages collection. The LEADDocument.Documents collection will still be an empty
collection since the page's original owner is the same document (in other words, DocumentPage.Document is virtualDocument).
The user adds a page from another document (document1) into LEADDocument.Pages of virtualDocument.
The LEADDocument.Documents collection will contain a single item: document1
The user adds another page from document1 into LEADDocument.Pages of virtualDocument.
The LEADDocument.Documents collection will still contain the single item document1 since both pages have the same owner.
The user adds a page from document2 into LEADDocument.Pages of virtualDocument.
The LEADDocument.Documents collection will contain two items: document1 and document2.
The user removes the last page from virtualDocument.
The LEADDocument.Documents collection will contain the single item document1.
The user removes all the pages from virtualDocument. The LEADDocument.Documents collection will be empty.
When LEADDocument.SaveToCache is called, the document will store the IDs of all the child documents.
When DocumentFactory.LoadFromCache is called, the document will try to re-load all the child documents and automatically add them into this collection. If any document fails to load or is no longer available in the cache, then all of its pages are removed automatically and are not loaded.
When the document is disposed, the value of AutoDisposeDocuments is examined. If it is true, then all the child documents are disposed as well.
using Leadtools;using Leadtools.Caching;using Leadtools.Document;public void DocumentFactoryCreateExample(){var cache = GetCache();// Create a new documentvar createOptions = new CreateDocumentOptions();createOptions.Cache = cache;createOptions.Descriptor = null;createOptions.MimeType = null;createOptions.UseCache = true;createOptions.UserId = null;Console.WriteLine("Cache Policy: {0}", createOptions.CachePolicy.AbsoluteExpiration);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); // DocumentDocuments reference// 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;}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}