Display name of the attachment.
public string DisplayName {get; set;}
The display name of the attachment. The default value is null.
DisplayName is parsed from the original document, and is optional. For attachments embedded in PDF documents, DisplayName will be equal to FileName.
For more information, refer to Document Attachments.
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 ExternalAttachmentsExample(){// The cache we are usingvar cache = new FileCache();cache.PolicySerializationMode = CacheSerializationMode.Json;cache.DataSerializationMode = CacheSerializationMode.Json;cache.CacheDirectory = @"c:\cache-dir";// The main document, its a PDFstring mainDocumentFile = @"C:\LEADTOOLS22\Resources\Images\leadtools.pdf";// Attachments we will be adding: a TIF, another PDF, and a JPG filestring[] attachmentFiles ={@"C:\LEADTOOLS22\Resources\Images\ocr1.tif",@"C:\LEADTOOLS22\Resources\Images\employee benefits survey.pdf",@"C:\LEADTOOLS22\Resources\Images\cannon.jpg"};// Load the main documentstring mainDocumentId;var loadDocumentOptions = new LoadDocumentOptions();loadDocumentOptions.Cache = cache;using (LEADDocument mainDocument = DocumentFactory.LoadFromFile(mainDocumentFile, loadDocumentOptions)){// Save the document ID so we can load it from cache latermainDocumentId = mainDocument.DocumentId;// Show this document, it should have no attachments at this pointShowDocumentWithAttachments("Initial", mainDocument, 0);mainDocument.IsReadOnly = false;// Now, load each attachment document and add it to the main documentforeach (string attachmentFile in attachmentFiles){int attachmentNumber = 1;using (LEADDocument attachmentDocument = DocumentFactory.LoadFromFile(attachmentFile, loadDocumentOptions)){// Save this document to the cacheattachmentDocument.AutoDeleteFromCache = false;attachmentDocument.SaveToCache();// Add it to the main document as an attachmentvar attachment = new DocumentAttachment();// The attachment number.attachment.AttachmentNumber = attachmentNumber;// This is an external attachmentattachment.IsEmbedded = false;// And the document IDattachment.DocumentId = attachmentDocument.DocumentId;// The rest of the properties are optional but setting them might be helpful to an application user interfaceattachment.FileName = attachmentDocument.Name;attachment.DisplayName = attachmentDocument.Name;attachment.FileLength = attachmentDocument.FileLength;attachment.MimeType = attachmentDocument.MimeType;mainDocument.Attachments.Add(attachment);attachmentNumber++;}}mainDocument.IsReadOnly = true;// Now, show the document info again, it should have 3 attachmentsShowDocumentWithAttachments("After adding attachments", mainDocument, attachmentFiles.Length);// Ensure that attachments will be deleted when the owner document is removedmainDocument.AutoDeleteAttachmentsFromCache = true;// Save this document to the cachemainDocument.AutoDeleteFromCache = false;mainDocument.SaveToCache();}// Re-load the main document from the cachevar loadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = mainDocumentId;using (LEADDocument mainDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Show this document, it should have the attachments we savedShowDocumentWithAttachments("Loaded from cache", mainDocument, attachmentFiles.Length);}// Another way of loading this attachment is with DocumentFactory.LoadDocumentAttachment using the attachment number.// This method can be used to load both external and embedded attachments using the owner document ID and the attachment number.Console.WriteLine("Using LoadDocumentAttachments:");for (var attachmentNumber = 1; attachmentNumber <= attachmentFiles.Length; attachmentNumber++){// For loading the main documentloadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = mainDocumentId;// For loading the attachmentvar loadAttachmentOptions = new LoadAttachmentOptions();loadAttachmentOptions.AttachmentNumber = attachmentNumber;using (LEADDocument attachmentDocument = DocumentFactory.LoadDocumentAttachment(loadFromCacheOptions, loadAttachmentOptions)){Console.WriteLine(" " + GetDocumentInfo(attachmentDocument));}}// Clean up by deleting the original document from the cache. This will cause all attachment documents to be deleted as well// Since we set AutoDeleteAttachmentsFromCache to true earlierloadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = mainDocumentId;DocumentFactory.DeleteFromCache(loadFromCacheOptions);}private static void ShowDocumentWithAttachments(string message, LEADDocument document, int attachmentCount){// Show info about this document and any attachmentsConsole.WriteLine(message);Console.WriteLine(" " + GetDocumentInfo(document));// Sanity checkDebug.Assert(attachmentCount == document.Attachments.Count);if (document.Attachments.Count > 0){Console.WriteLine(" Attachments:");// Show the attachmentsforeach (DocumentAttachment attachment in document.Attachments){// Load the attachment as a LEADDocument using the document ID// This method works for external attachments onlyvar loadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = document.GetCache();loadFromCacheOptions.DocumentId = attachment.DocumentId;using (LEADDocument attachmentDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)){Console.WriteLine(" " + GetDocumentInfo(attachmentDocument));}}}}private static string GetDocumentInfo(LEADDocument document){return $"DocumentId:{document.DocumentId} MimeType:{document.MimeType} Pages:{document.Pages.Count} Attachments:{document.Attachments.Count}";}