←Select platform

UserGetDocumentStatusHandler Delegate

Summary

MIME whitelist user defined callback type.

Syntax
C#
C++/CLI
Python
delegate DocumentMimeTypeStatus UserGetDocumentStatusHandler( 
   Uri uri, 
   LoadDocumentOptions options, 
   DocumentMimeTypeSource source, 
   string mimeType 
) 
public: 
   delegate DocumentMimeTypeStatus UserGetDocumentStatusHandler( 
      Uri^ uri, 
      LoadDocumentOptions^ options, 
      DocumentMimeTypeSource^ source, 
      String^ mimeType 
   ) 
def UserGetDocumentStatusHandler(self,uri,options,source,mimeType): 
# uri : Uri, options : LoadDocumentOptions, source : DocumentMimeTypeSource, mimeType : String 

Parameters

uri

The URI to the document being loaded.

options

The object passed by the user.

source

The source of this callback invocation.

mimeType

The MIME type being checked

Return Value

Call GetDocumentStatus to continue with the current settings or any other values to manually allow/deny the MIME type.

Remarks

By default, Entries does not contain any entries and the value of DefaultStatus is Unspecified. Therefore, DocumentFactory is able to load any data containing an image or document format supported by LEADTOOLS.

Refer to DocumentMimeTypes to customize this behavior.

Example
C#
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 MimeTypesWhitelistExample() 
{ 
   // Documents to try and load 
   string[] urls = 
   { 
      "https://demo.leadtools.com/images/pdf/leadtools.pdf", 
      "https://demo.leadtools.com/images/tiff/ocr.tif", 
      "https://demo.leadtools.com/images/png/pngimage.png" 
    }; 
 
   // Setup a callback for logging 
   // DocumentMimeTypes & DocumentMimeTypes.UserGetDocumentStatusHandler reference 
   DocumentMimeTypes.UserGetDocumentStatusHandler userGetDocumentStatus = (Uri uri, LoadDocumentOptions options, DocumentMimeTypeSource source, string mimeType) => 
   { 
      // Use default operation 
      DocumentMimeTypeStatus status = DocumentFactory.MimeTypes.GetDocumentStatus(uri, options, source, mimeType); 
      string mimeTypeValue = mimeType != null ? mimeType : "[null]"; 
      DocumentFactory.MimeTypes.GetStatus(mimeTypeValue); 
      Console.WriteLine(string.Format("  ** Whitelist url:{0} source:{1} mimeType:{2} status:{3}", uri.ToString(), source, mimeTypeValue, status)); 
 
      return status; 
   }; 
 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = userGetDocumentStatus; 
 
   // Load the documents, by default we should load all of them 
   Console.WriteLine("Everything should load OK"); 
   LoadDocuments(urls); 
 
   // Now, disable loading everything except PDF and TIFF and try again 
   Console.WriteLine("Disabling everything except PDF and TIFF"); 
   DocumentFactory.MimeTypes.DefaultStatus = DocumentMimeTypeStatus.Denied; 
   DocumentFactory.MimeTypes.Entries.Add("application/pdf", DocumentMimeTypeStatus.Allowed); 
   DocumentFactory.MimeTypes.Entries.Add("image/tiff", DocumentMimeTypeStatus.Allowed); 
   Console.WriteLine("Only PDF and TIFF should be loaeded"); 
   LoadDocuments(urls); 
 
   // Reset 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = null; 
} 
 
private static void LoadDocuments(string[] urls) 
{ 
   var loadDocumentOptions = new LoadDocumentOptions(); 
 
   foreach (var url in urls) 
   { 
      Console.WriteLine(" Loading " + url); 
      using (var document = DocumentFactory.LoadFromUri(new Uri(url), loadDocumentOptions)) 
      { 
         if (document != null) 
            Console.WriteLine("  is Loaded"); 
         else 
            Console.WriteLine("  cannot be loaded"); 
      } 
   } 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Document Namespace

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

Leadtools.Document Assembly

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