←Select platform

DisplayName Property

Summary

Display name of the attachment.

Syntax
C#
C++/CLI
Python
public string DisplayName {get; set;} 
public:  
   property String^ DisplayName 
   { 
      String^ get() 
      void set(String^ value) 
   } 
DisplayName # get and set (DocumentAttachment) 

Property Value

The display name of the attachment. The default value is null.

Remarks

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.

Example
C#
Java
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 using 
   var cache = new FileCache(); 
   cache.PolicySerializationMode = CacheSerializationMode.Json; 
   cache.DataSerializationMode = CacheSerializationMode.Json; 
   cache.CacheDirectory = @"c:\cache-dir"; 
 
   // The main document, its a PDF 
   string mainDocumentFile = @"C:\LEADTOOLS22\Resources\Images\leadtools.pdf"; 
 
   // Attachments we will be adding: a TIF, another PDF, and a JPG file 
   string[] attachmentFiles = 
   { 
      @"C:\LEADTOOLS22\Resources\Images\ocr1.tif", 
      @"C:\LEADTOOLS22\Resources\Images\employee benefits survey.pdf", 
      @"C:\LEADTOOLS22\Resources\Images\cannon.jpg" 
   }; 
 
   // Load the main document 
   string 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 later 
      mainDocumentId = mainDocument.DocumentId; 
 
      // Show this document, it should have no attachments at this point 
      ShowDocumentWithAttachments("Initial", mainDocument, 0); 
 
      mainDocument.IsReadOnly = false; 
      // Now, load each attachment document and add it to the main document 
      foreach (string attachmentFile in attachmentFiles) 
      { 
         int attachmentNumber = 1; 
         using (LEADDocument attachmentDocument = DocumentFactory.LoadFromFile(attachmentFile, loadDocumentOptions)) 
         { 
            // Save this document to the cache 
            attachmentDocument.AutoDeleteFromCache = false; 
            attachmentDocument.SaveToCache(); 
 
            // Add it to the main document as an attachment 
            var attachment = new DocumentAttachment(); 
            // The attachment number. 
            attachment.AttachmentNumber = attachmentNumber; 
            // This is an external attachment 
            attachment.IsEmbedded = false; 
            // And the document ID 
            attachment.DocumentId = attachmentDocument.DocumentId; 
 
            // The rest of the properties are optional but setting them might be helpful to an application user interface 
            attachment.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 attachments 
      ShowDocumentWithAttachments("After adding attachments", mainDocument, attachmentFiles.Length); 
 
      // Ensure that attachments will be deleted when the owner document is removed 
      mainDocument.AutoDeleteAttachmentsFromCache = true; 
      // Save this document to the cache 
      mainDocument.AutoDeleteFromCache = false; 
      mainDocument.SaveToCache(); 
   } 
 
   // Re-load the main document from the cache 
   var loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.Cache = cache; 
   loadFromCacheOptions.DocumentId = mainDocumentId; 
   using (LEADDocument mainDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)) 
   { 
      // Show this document, it should have the attachments we saved 
      ShowDocumentWithAttachments("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 document 
      loadFromCacheOptions = new LoadFromCacheOptions(); 
      loadFromCacheOptions.Cache = cache; 
      loadFromCacheOptions.DocumentId = mainDocumentId; 
 
      // For loading the attachment 
      var 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 earlier 
   loadFromCacheOptions = 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 attachments 
   Console.WriteLine(message); 
   Console.WriteLine("  " + GetDocumentInfo(document)); 
 
   // Sanity check 
   Debug.Assert(attachmentCount == document.Attachments.Count); 
 
   if (document.Attachments.Count > 0) 
   { 
      Console.WriteLine("    Attachments:"); 
 
      // Show the attachments 
      foreach (DocumentAttachment attachment in document.Attachments) 
      { 
         // Load the attachment as a LEADDocument using the document ID 
         // This method works for external attachments only 
         var 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}"; 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void attachmentsDocumentIdExample() { 
 
   // The cache we are using 
   FileCache cache = new FileCache(); 
   cache.setPolicySerializationMode(CacheSerializationMode.JSON); 
   cache.setDataSerializationMode(CacheSerializationMode.JSON); 
   cache.setCacheDirectory("c:\\cache-dir"); 
 
   // The main document, its a PDF 
   String mainDocumentFile = "C:\\LEADTOOLS23\\Resources\\Images\\leadtools.pdf"; 
 
   // Attachments we will be adding: a TIF, another PDF, and a JPG file 
   String[] attachmentFiles = { 
         "C:\\LEADTOOLS23\\Resources\\Images\\ocr1.tif", 
         "C:\\LEADTOOLS23\\Resources\\Images\\employee benefits survey.pdf", 
         "C:\\LEADTOOLS23\\Resources\\Images\\cannon.jpg" 
   }; 
 
   // Load the main document 
   String mainDocumentId; 
   LoadDocumentOptions loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.setCache(cache); 
   LEADDocument mainDocument = DocumentFactory.loadFromFile(mainDocumentFile, loadDocumentOptions); 
 
   // Save the document ID so we can load it from cache later 
   mainDocumentId = mainDocument.getDocumentId(); 
 
   // Show this document, it should have no attachments at this point 
   showDocumentWithAttachments("Initial", mainDocument, 0); 
   mainDocument.setReadOnly(false); 
   // Now, load each attachment document and add it to the main document 
   for (String attachmentFile : attachmentFiles) { 
      int attachmentNumber = 1; 
      LEADDocument attachmentDocument = DocumentFactory.loadFromFile(attachmentFile, loadDocumentOptions); 
      // Save this document to the cache 
      attachmentDocument.setAutoDeleteFromCache(false); 
      attachmentDocument.saveToCache(); 
 
      // Add it to the main document as an attachment 
      DocumentAttachment attachment = new DocumentAttachment(); 
      // The attachment number. 
      attachment.setAttachmentNumber(attachmentNumber); 
      // This is an external attachment 
      attachment.setEmbedded(false); 
      // And the document ID 
      attachment.setDocumentId(attachmentDocument.getDocumentId()); 
 
      // The rest of the properties are optional but setting them might be helpful to 
      // an application user interface 
      attachment.setFileName(attachmentDocument.getName()); 
      attachment.setDisplayName(attachmentDocument.getName()); 
      attachment.setFileLength(attachmentDocument.getFileLength()); 
      attachment.setMimeType(attachmentDocument.getMimeType()); 
 
      mainDocument.getAttachments().add(attachment); 
      attachmentNumber++; 
   } 
   mainDocument.setReadOnly(true); 
 
   // Now, show the document info again, it should have 3 attachments 
   showDocumentWithAttachments("After adding attachments", mainDocument, attachmentFiles.length); 
 
   // Ensure that attachments will be deleted when the owner document is removed 
   mainDocument.setAutoDeleteAttachmentsFromCache(true); 
   // Save this document to the cache 
   mainDocument.setAutoDeleteFromCache(false); 
   mainDocument.saveToCache(); 
 
   // Re-load the main document from the cache 
   LoadFromCacheOptions loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(mainDocumentId); 
 
   mainDocument = DocumentFactory.loadFromCache(loadFromCacheOptions); 
 
   // Show this document, it should have the attachments we saved 
   showDocumentWithAttachments("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. 
   System.out.println("Using LoadDocumentAttachments:"); 
   for (int attachmentNumber = 1; attachmentNumber <= attachmentFiles.length; attachmentNumber++) { 
      // For loading the main document 
      loadFromCacheOptions = new LoadFromCacheOptions(); 
      loadFromCacheOptions.setCache(cache); 
      loadFromCacheOptions.setDocumentId(mainDocumentId); 
 
      // For loading the attachment 
      LoadAttachmentOptions loadAttachmentOptions = new LoadAttachmentOptions(); 
      loadAttachmentOptions.setAttachmentNumber(attachmentNumber); 
 
      LEADDocument attachmentDocument = DocumentFactory.loadDocumentAttachment(loadFromCacheOptions, 
            loadAttachmentOptions); 
      System.out.println("  " + 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 earlier 
   loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(mainDocumentId); 
   DocumentFactory.deleteFromCache(loadFromCacheOptions); 
 
} 
 
private static void showDocumentWithAttachments(String message, LEADDocument document, int attachmentCount) { 
 
   // Show info about this document and any attachments 
   System.out.println(message); 
   System.out.println("  " + getDocumentInfo(document)); 
 
   // Sanity check 
   assertTrue(attachmentCount == document.getAttachments().size()); 
 
   if (document.getAttachments().size() > 0) { 
      System.out.println("    Attachments:"); 
 
      // Show the attachments 
      for (DocumentAttachment attachment : document.getAttachments()) { 
         // Load the attachment as a LEADDocument using the document ID 
         // This method works for external attachments only 
         LoadFromCacheOptions loadFromCacheOptions = new LoadFromCacheOptions(); 
         loadFromCacheOptions.setCache(document.getCache()); 
         loadFromCacheOptions.setDocumentId(attachment.getDocumentId()); 
         LEADDocument attachmentDocument = DocumentFactory.loadFromCache(loadFromCacheOptions); 
 
         System.out.println("      " + getDocumentInfo(attachmentDocument)); 
      } 
   } 
} 
 
private static String getDocumentInfo(LEADDocument document) { 
   return "DocumentId:" + document.getDocumentId() + " MimeType:" + document.getMimeType() + " Pages:" 
         + document.getPages().size() + " Attachments:" + document.getAttachments().size(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.