WebTWAIN II ActiveX Control Overview
 

WARNING:WebTWAIN II is deprecated due to changes that Microsoft made to Internet Explorer. It is no longer supported!

WebTWAIN II is an ActiveX control that primarliy provides for image aquisition from a TWAIN source. It was specifically designed to be used in combination with an image uploading Webpage and provides additional functionality to accomplish this. The control is useful in Web-based applications where users are required to scan a document or image for uploading to a remote webserver, such as legal documents, received invoices etc. Image & File uploading are well known and widely used web application constructs. Talking to a TWAIN source and generating a file directly compatible with browser-based file uploading is however not. With the WebTWAIN control, you can embed the scanning functionality directly into your webpage and still perform the file uploading according to standard uploading mechanisms. This means that you can directly perform scanning from within your Webpage.


Communicating with a TWAIN source is not difficult and is pretty much common knowledge. If you have some basic programming skills, you could write this ActiveX control yourself. What makes WebTWAIN different though, is its ability to insert values into an HTML form's <INPUT TYPE=FILE> file input box. As anyone that has tried to script an <INPUT TYPE=FILE> input box knows, the input box cannot be made to respond to script instructions to give it a value. It is not difficult to see why : If the value of the file input box could be scripted, it would be pretty easy to write a malicious webpage that uploads any file on the client computer to a webserver. Although this is good for general security, it is a pain in the backside for anyone implementing file generation intended for file upload through an ActiveX Control. To overcome this, WebTWAIN contains functionality to get the name of the scanned file into a file upload box. This is done through a combination of script and an ActiveX Control method (and no, it's not sendkeys ;)

NOTE : This control only works with Internet Explorer 32 bit V4.0 and above!!!

 
WebTWAIN II New Features
 


WebTWAIN II in Graphic Button Style
 

Through the years, WebTWAIN has been enhanced in various ways. First of all, it has gained resizing abilities so that you can size it to whatever your application requirements demand. Secondly, we've provided WebTWAIN with a graphic button look in addition to the standard text buttons. The graphic buttons take up substantially less space than the text buttons and are useful when your screen space is at a premium. It also provides WebTWAIN with a very basic form of language independence because the graphic symbols are not tied to any specific language.

We've further found that WebTWAIN lends itself very well to document management applications. The convenience of scanning directly from a webpage makes capturing of corporate paper documents and/or faxes ideal in the implementation of CRM or Accounting systems. To make it even more flexible, we've also made WebTWAIN accept pasted images from the clipboard. This is performed by right clicking on the image portion of WebTWAIN. This pops up a little menu with an item Paste Image. So instead of scanning an image from a TWAIN device, you can paste images into WebTWAIN as if they were scanned. Why is this useful? Well, in our business we often purchase items and services online. All this is done via the Web, but after a purchase we would like a record of the items purchased within our job tracking system. By pressing ALT-PrintScreen on the window where the purchase results are, the contents of the window is copied onto the clipboard. By pasting such an image into WebTWAIN now, we have a document record of the on-screen purchase information. The nicer thing is that this "pasted" document is handled in exactly the same way as our scanned documents.

 

Adding the Paste functionality made us wonder whether we could not also get WebTWAIN to handle text information. After all, often one also wishes to capture a simple piece of text such as an email in a standard document way. So we added text capture functionality to WebTWAIN as well. This is implemented by allowing WebTWAIN to operate in one of two modes : Scan Mode and Text Mode. Scan Mode provides the Scan and Image Paste functionality, while text mode provides text capture functionality. When operating in text mode, the control has no way of knowing when the text capture has been completed. Hence, the user needs to click on the Done button to finalise a text capture. A mode change button on the control allows easy switching between the two modes. Of course, pasting text is not a difficult function to implement with standard web elements such as a <TEXTAREA>. However, because WebTWAIN handles scans, pasted images and text pastes in exactly the same manner, it can act as a universal document capture object.

Two other enhancements are present in WebTWAIN II. The first of these is the implementation of FTP functionality. This allows the control to FTP acquired images (or text documents) to an FTP Server. This is useful in cases where one does not want to use forms-based file uploading. The other allows WebTWAIN to save acquired images not as JPG images, but as timestamped PDF Files. The latter is useful if you prefer working with PDF documents than JPG images.

 

WebTWAIN II in Text Capture Mode
 
Relevant WebTWAIN II Control Properties, Methods and Events
 
Property ButtonStyle As LongButtonStyleSets the style of buttons on the control (0=Graphical,1=Text). Defaults to Graphical (0).
Property ControlMode As LongControlModeSets the Mode of the Control (0=Scan Mode,1=Text Capture Mode). Defaults to Scan Mode (0).
Property CurrentName As StringCurrentNameReturns the name of the file last generated by WebTWAIN II.
Property FilePath As StringFilePathSets the path to which the aquired image will be saved. For example, if you set this to "c:\" then the WebTWAIN control will write the acquired image to the file "c:\scanx.jpg". This property defaults to "c:\".
Property FullScreen As LongFullScreenSets whether the image portion of the control extends over the full size of the control (1) or not (0). Useful when wanting to prevent the user from accessing the control buttons. Defaults to 0.
Property ImageHeight As Long (read-only)ImageHeightRead-Only Property that returns the height (in pixels) of the last acquired image. Useful to check whether your user has scanned an image that meets your requirements.
Property ImageWidth As Long (read-only)ImageWidthRead-Only Property that returns the width (in pixels) of the last acquired image. Useful to check whether your user has scanned an image that meets your requirements.
Property ImageSize As Long (read-only)ImageSizeRead-Only Property that returns the file size (in bytes) of the last acquired image. Useful to check that your user does not scan a monster sized file or to adjust your ASP script timeout value to allow the file upload process to run long enough.
Sub PasteName()PasteName()This method will paste the acquired file name to the control's parent window. For Internet Explorer, this will be to the form element that has the focus at the time the method is invoked. This is illustrated in the example below.
Property Quality As LongQualityThis property determines the JPEG quality value that will be used when compressing the acquired image. It may assume a number between 0 and 100 and defaults to 60.
Property SaveAsPDF As variantSaveAsPDFControls whether scans are saved as JPG (False) or PDF (True) Files. Defaults to False.
Event ScanComplete(FileName)ScanComplete(FileName)This event is fired when a TWAIN acquisition has successfully been completed. The event provides a parameter that specifies the full filename of the file that the control created.
Sub SetSize(xWidth As Long, yHeight As Long)SetSize(Width,Height)Sets the size of the control to width x height pixels.
Property ShowModeButton As VariantShowModeButtonSpecifies whether the control should show (True) the Mode Change button or not (False). Defaults to True.
Sub StartScan()StartScan()Allows you to initiate a scan from external script. Useful when the control is running FullScreen.
Function UploadFile(vServer As Variant, vUserName As Variant, vPassword As Variant, Optional vFTPMode As Variant = 0, Optional vRemoteFileName As Variant = '', Optional vRemoteDirectory As Variant = '') As StringUploadFile(Svr, UName, Passwd, [Mode], [RemoteName], [RemoteDir])Attempts uploading of the acquired JPG,PDF or txt file to a remote FTP Server. The parameters are:
Svr : FQDN or IP Address of FTP Server
UName : FTP UserName
Passwd : FTP Password
Mode : FTP Transfer Mode (0 = Active (Def), 1 = Passive)
RemoteName : Remote filename (defaults to scanx.jpg, scanx.pdf or scanx.txt)
RemoteDir : (No default)

The function returns a string value that is of zero length if the upload was successful. If any errors occurred, then the function return string contains an applicable errormessage.
 
Sample HTML code for using the control
 
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onLoad()
  document.X.WebTWAIN2.ControlMode = 0
  document.X.WebTWAIN2.FilePath = "c:\"
  document.X.WebTWAIN2.Quality = 80
  document.X.WebTWAIN2.SaveAsPDF = False
  document.X.WebTWAIN2.ShowModeButton = True
  document.X.WebTWAIN2.SetSize 300,300
End Sub
-->
</SCRIPT>
<TITLE>WebTWAIN II Sample</TITLE>
</HEAD>

<BODY BGCOLOR=CYAN>
<CENTER>
<FORM ACTION="myfileuploader.asp" METHOD="POST" ENCTYPE="multipart/form-data" NAME="X">
<TABLE BORDER=1>
<TR>
  <TD>
    <SCRIPT LANGUAGE="VBScript">
    <!--
    Sub WebTWAIN2_ScanComplete(FileName)
      Dim ICount
      Dim M
      Dim R 
      Dim Server
      Dim UserName
      Dim Password
      M = "A Document named "
      M = M & document.X.WebTWAIN2.CurrentName
      M = M & " (" & document.X.WebTWAIN2.ImageSize & " bytes) "
      M = M & "was successfully acquired."
      M = M & vbcrlf & vbcrlf
      M = M & "Do you wish to FTP this to a remote FTP Server ?"
      R = MsgBox(M,vbQuestion + vbYesNo,"Please Confirm")
      If R = vbYes Then
        M = "Please enter the FTP Server's IP Address or Name"
        Server = InputBox(M,"Server Address")
        Setver = Trim(Server)
        If Len(Server) > 0 Then
          M = "Please enter your FTP Username"
          UserName = InputBox(M,"UserName")
          UserName = Trim(UserName)
          If Len(UserName) > 0 Then
            M = "Please enter your FTP Password"
            Password = InputBox(M,"Password")
            Password = Trim(Password)
            If Len(Password) > 0 Then
              M = ""
              M = document.X.WebTWAIN2.UploadFile(Server,UserName,Password)
              If Len(M) > 0 Then
                M = "The FTP Transfer Failed with the following error : " & M
                MsgBox M,vbCritical,"FTP Failed"
              Else
                M = "The File was successfully FTP'ed"
                MsgBox M,vbInformation
              End If
            End If
          End If
        End If
      End If

      M = "Do you wish to paste the Filename into the HTML Form ?"
      R = MsgBox(M,vbQuestion + vbYesNo,"Please Confirm")
      If R = vbYes Then	
        document.X.doc.focus()
        document.X.WebTWAIN2.PasteName()
      End If
   End Sub
   -->
   </SCRIPT>
   <OBJECT ID="WebTWAIN2"
   CLASSID="CLSID:9779A3F5-EFF7-11D6-9AFF-0060085AA461"
   CODEBASE="WebTWAIN2.CAB#version=1,0,0,22">
   </OBJECT>
   </TD>
</TR>
<TR>
  <TD>
    <INPUT TYPE=FILE SIZE=20 NAME="doc">
  </TD>
</TR>
</TABLE>
</FORM>
</CENTER>
</BODY>
</HTML>
 
Downloads

The WebTWAIN II ActiveX Control is available in two download types. The first is a CAB file that can be distributed directly from your webserver. The CAB file is signed and installs automatically on a client browser when encountered in your HTML. Note that it is prudent to tell your clients to wait for such installations to finish!. If installation fails due to user aborts, it will NOT install again next time round. Note also that the download and installation will only occur the first time. On subsequent visits to the page, the control will appear immediately.

The second download is a traditional setup program for the control. To use this, the program setup.exe needs to be run manually to install the ActiveX Control on the client's machine. This setup package is distributed with all its necessary files in a zip format.

 
Redistributable Installation CAB File (Zip of Signed installation CAB)4,616,729 bytes
Traditional ActiveX Control Setup Package (Needs to be run manually on client computers)4,866,048 bytes
Sample of the control in action (Opens in new window - please be patient as around 4.5 MByte will be downloaded on the first use of the control)Initial ±4.5 MB Download
 
Revision History

WebTWAIN has had a coloured revision history. The original version was distributed as a donationware component. Although some very kind people did bother to donate, thousands more downloaded without any contribution whatsoever. This prompted me to discontinue the donationware concept and make the control shareware with registration. As it stands right now, the control is fully functional with a nag screen reminder to register.

 
31 Dec 2010WebTWAIN II officially discontinued. Thanks to Microsoft for breaking it with Vista and Internet Explorer 7. Moved to Linux 2 years ago.
31 Jan 2003With MSIE6, it would seem that the control does not properly resize if the Resize Method is the first one called after loading the control. This does not happen with IE5 and 5.5. As a result, please don't call the SetSize method as your first control method or property. Sample code patched to reflect this. Thanks to Jim Cox for identifying this.
4 Nov 2002Added FullScreen Property and StartScan Method. Updated release to V1.0.22
3 Nov 2002Released NagScreen Shareware Version and renamed to WebTWAIN II. Version renumbered to 1.0.21
7 Sep 2002WebTWAIN distribution stopped due to lack of donations. My digital certificate is about to expire.
6 Nov 2001Released Signed Version of WebTWAIN ActiveX Control
28 Mar 2001Updated to V1.0.20 to fix erroneous height reporting
26 Mar 2001Initial Release V1.0.18
 
Build & Resource Information

The WebTWAIN II ActiveX Control was built with a variety of commercial and freeware tools. These are:

 
Primary Build Tool Visual Basic 6.0 SP5
TWAIN Library EZTwain 1.06
JPEG Compression Intel® JPEG Library
JPEG Wrapper SaveJPEG Project
PDF Support PDF ImageStream
Scaled Image Display ImageScaler 6.4
 
Disclaimer

This ActiveX Control is provided as is and without any guarantees or promises. You use it entirely at your own risk. It was written with care and was not designed to do anything clandestine or trojan like. It does nothing but try and talk to a TWAIN or Text source, convert an acquired image to a JPG or PDF and write the resulting file (named scanx.jpg, scanx.pdf or scanx.txt) to the directory as specified. However, it cannot be assumed to be bug or error free. You also cannot hold me responsible if it crashes your machine, corrupts your registry, destroys your Micosoft Visual Studio 6.0 SP5 (which it was built on). By using or distributing the control, you acknowledge to hold the author free of any claims arising from the use of the control or any other reason.

 
Contact Information

This Webpage was written in a great hurry, so please don't judge the control on the appearance of this page. One day when I grow up, I'll make a decent page. But then, it is only a tiny page for an ActiveX Control, not a corporate PR page ;). If you wish to mail me any comments, feel free to do so at stefan@internext.co.za

accesses since 26 March 2001