←Select platform

DocumentId Property

Summary

The ID to be used with the loaded document.

Syntax
C#
C++/CLI
Java
Python
public string DocumentId { get; set; } 
public:  
   property String^ DocumentId 
   { 
      String^ get() 
      void set(String^ value) 
   } 
public String getDocumentId() 
public void setDocumentId() 
DocumentId # get and set (UploadDocumentOptions) 

Property Value

String that specifies the ID to be used with the loaded document. Default value is null.

Remarks

When the value of DocumentId is null (the default), then the document factory will create a new unique ID using a GUID generator (DocumentFactory.NewCacheId). If the value is not null, then it is assumed to be a user-defined ID and used as is. In either case, the value is set in the LEADDocument.DocumentId property of the newly created document.

User-defined IDs can be used when the system already have unique ID's associated with the documents to be viewer. The document factory will not check nor guarantee the uniqueness of these IDs.

Refer to Uploading Using the Document Library for detailed information.

Example
C#
Java
using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
 
 
public void DocumentFactoryBeginUploadExample() 
{ 
   var cache = GetCache(); 
 
   // Upload the document in 32K chunks 
   const int bufferSize = 1024 * 32; 
   var buffer = new byte[bufferSize]; 
 
   var fileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
   Uri uploadUri = null; 
   using (var reader = File.OpenRead(fileName)) 
   { 
      // Start uploading 
      var uploadOptions = new UploadDocumentOptions(); 
      uploadOptions.Cache = cache; 
      // Optional: set the mime type of the document we are uploading. 
      // If this value is not provided or is wrong then it will be overridden by the factory when LoadFromUri is called. 
      uploadOptions.MimeType = "application/pdf"; 
      // Optional: set the name of the document, the same name as the file. 
      // This value is only important as a hint when the document file data does not contain a valid signature, such as TXT or XML files 
      uploadOptions.Name = "Leadtools.pdf"; 
      uploadOptions.CachePolicy = new CacheItemPolicy(); 
      uploadOptions.DocumentId = null; 
      uploadOptions.PageCount = 0; 
      uploadUri = DocumentFactory.BeginUpload(uploadOptions); 
 
      int bytes; 
      do 
      { 
         bytes = reader.Read(buffer, 0, bufferSize); 
         if (bytes > 0) 
         { 
            // Upload a chunk 
            DocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, bytes); 
 
            // Upload annotations 
            DocumentFactory.UploadAnnotations(cache, uploadUri, buffer, 0, bytes); 
         } 
      } 
      while (bytes > 0); 
   } 
 
   // We are done, this method is optional, we can call LoadFromUri right now 
   DocumentFactory.EndUpload(cache, uploadUri); 
   DocumentFactory.AbortUploadDocument(uploadUri); 
 
   // Now load the document 
   var options = new LoadDocumentOptions(); 
   options.Cache = cache; 
   using (var document = DocumentFactory.LoadFromUri(uploadUri, options)) 
   { 
      PrintOutDocumentInfo(document); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.util.Calendar; 
 
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.caching.*; 
import leadtools.document.*; 
 
 
public void documentFactoryBeginUploadExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   FileCache cache = getCache(); 
 
   // Upload the document in 32K chunks 
   final int bufferSize = 1024 * 32; 
   byte[] buffer = new byte[bufferSize]; 
   String fileName = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   URI uploadUri = null; 
   InputStream inputStream = new FileInputStream(fileName); 
   LeadStream reader = new LeadStream(inputStream, false); 
 
   // Start uploading 
   UploadDocumentOptions uploadOptions = new UploadDocumentOptions(); 
   uploadOptions.setCache(cache); 
   // Optional: set the mime type of the document we are uploading. 
   // If this value is not provided or is wrong then it will be overridden by the 
   // factory when LoadFromUri is called. 
   uploadOptions.setMimeType("application/pdf"); 
   // Optional: set the name of the document, the same name as the file. 
   // This value is only important as a hint when the document file data does not 
   // contain a valid signature, such as TXT or XML files 
   uploadOptions.setName("Leadtools.pdf"); 
   uploadOptions.setCachePolicy(new CacheItemPolicy()); 
   uploadOptions.setDocumentId(null); 
   uploadOptions.setPageCount(0); 
   uploadUri = DocumentFactory.beginUpload(uploadOptions); 
 
   int bytes; 
   do { 
      bytes = reader.read(buffer, bufferSize); 
      if (bytes > 0) { 
         // Upload a chunk 
         DocumentFactory.uploadDocument(cache, uploadUri, buffer, 0, bytes); 
 
         // Upload annotations 
         DocumentFactory.uploadAnnotations(cache, uploadUri, buffer, 0, bytes); 
      } 
   } while (bytes > 0); 
   reader.dispose(); 
   reader.close(); 
   inputStream.close(); 
 
   // We are done, this method is optional, we can call LoadFromUri right now 
   DocumentFactory.endUpload(cache, uploadUri); 
   DocumentFactory.abortUploadDocument(uploadUri); 
 
   // Now load the document 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   options.setCache(cache); 
   LEADDocument document = DocumentFactory.loadFromUri(uploadUri, options); 
   printOutDocumentInfo(document); 
   assertTrue(document != null); 
   System.out.println("Document created successfully"); 
   document.dispose(); 
} 
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.