Page tree
    Created with Raphaël 2.1.0
    Loading...
Skip to end of metadata
Go to start of metadata

Description

User-assigned delegate method that allows users to provide an implementation for retrieving the contents of an image and passing it back to HTMLToWord for insertion into a document. If not set, then HTMLToWord will not insert images into a document.
C#
public GetImageDelegate ImageDelegate{ get; set; }
vb.net
Public Property ImageDelegate() As GetImageDelegate

Examples

C#
System.IO.Stream MyImageGetter(string URI)
{
     //--- Check if there is data in the supplied URI.
     if (URI == null || URI.Length == 0)
     {
          //--- No URI or empty URI.  Nothing for us to do.
          //--- Indicate that there are no image contents.
          return null;
     }
 
     //--- Create a web request object to fetch the image file.
     WebRequest request;
     try
     {
          request = WebRequest.Create(URI);
          request.Method = "GET";
          request.Timeout = 5000;   // in milliseconds
     }
     catch (Exception e)
     {
          Console.WriteLine("Image (" + URI + ") ignored: " + e.Message);
          return null;
     }
 
     //--- Get the file and return the stream.
     System.IO.Stream s = null;
     try
     {
          s = request.GetResponse().GetResponseStream();
     }
     catch (WebException e)
     {
          Console.WriteLine("Image (" + URI + ") ignored: " + e.Message);
          return null;
     }
     catch (Exception e)
     {
          Console.WriteLine("Image (" + URI + ") ignored: " + e.Message);
          return null;
     }
 
     //--- We have successfully retrieved the image contents.
     //--- Pass the stream back to HTMLToWord.
     return s;
}
 
 
 
//--- Create an HTMLToWord instance.
HTMLToWord h2w = new HTMLToWord();
  
//--- Tell HTMLToWord that it should call our "MyImageGetter" delegate method
//-- whenever it encounters an img tag in the XHTML string.
h2w.ImageDelegate = new HTMLToWord.GetImageDelegate(MyImageGetter);
vb.net
Function MyImageGetter(string URI) As System.IO.Stream
     '--- Check if there is data in the supplied URI.
     If URI Is Nothing Or URI.Length = 0 Then
          '--- No URI or empty URI.  Nothing for us to do.
          '--- Indicate that there are no image contents.
          return Nothing
     End If
 
     '--- Create a web request object to fetch the image file.
     Dim request As WebRequest
     Try
          request = WebRequest.Create(URI)
          request.Method = "GET"
          request.Timeout = 5000   ' in milliseconds
     Catch e As Exception
          return Nothing
     End Try
 
     '--- Get the file and return the stream.
     Dim s As System.IO.Stream = Nothing
     Try
          s = request.GetResponse().GetResponseStream()
     Catch e As WebException
          return Nothing
     Catch e As Exception
          return Nothing
     End Try
 
     '--- We have successfully retrieved the image contents.
     '--- Pass the stream back to HTMLToWord.
     return s
End Function
 
 
 
'--- Create an HTMLToWord instance.
Dim h2w As New HTMLToWord()
  
'--- Tell HTMLToWord that it should call our "MyImageGetter" delegate method
'--- whenever it encounters an img tag in the XHTML string.
h2w.ImageDelegate = New HTMLToWord.GetImageDelegate(AddressOf MyImageGetter)
  • No labels