EZTwain Pro - Scanning from Visual Basic

Scanning from a scanner with an ADF (Automatic Document Feeder) using EZTwain Pro is very simple.

The following code samples were generated by our Code Wizard, which is included in the EZTwain Pro toolkit. The Code Wizard can generate code in a number of languages, including C, C++/MFC, Delphi, C#, VB, VB.NET, LotusScript, PowerScript, pseudo-code, and Visual FoxPro. The following code examples should work with VB 5, 6 or 7, and will probably run in VBA as well. Before you generate any code, the Code Wizard coaches you through bringing the EZTwain Pro declarations into your module. For VB, this just involves adding our EZTwain.bas module to your project.

First, here's the absolutely simplest code for scanning - you don't really need the Code Wizard to write this:

     ' Open the scanner, scan until user closes the scan dialog, collect the
     ' scans in the given PDF file, use whatever settings the user chooses.

     Call TWAIN_AcquireMultipageFile(Me.hwnd, "c:\testscan.pdf")

For a more complicated example, we walked through the Code Wizard screens selecting the following options:

Programming language: VB 5, 6 or 7
Work with "Any ADF scanner"
Scan from the default TWAIN device
Get all available images (i.e. scan until ADF is empty)
     Image format: Black & White (1 bit per pixel)
     Resolution: 200 DPI
     Duplex: Not specified
     Paper Source: ADF (some scanners can scan from either ADF or flatbed)
     Area to Scan: A region 3 inches wide by 2 inches high, starting 5 inches down from the top of the page.
Collect output in a single PDF file
Hide the user interface of the scanner
Allow the scanner's progress bar to be displayed
Write a diagnostic log (good idea until we are sure everything works perfectly.)

Dim fileName As String
fileName = "c:\SCAN_DOC.pdf"
Call TWAIN_LogFile(1)
Call TWAIN_SetHideUI(1)
If TWAIN_OpenDefaultSource()=1 Then
     Call TWAIN_SelectFeeder(1)
     Call TWAIN_SetPixelType(0)
     Call TWAIN_SetBitDepth(1)
     Call TWAIN_SetResolution(200)
     Call TWAIN_SetAutoScan(1)
     Call TWAIN_SetRegion(0, 5, 3, 7)
     Call TWAIN_AcquireMultipageFile(Me.hwnd, fileName)
End If
If TWAIN_LastErrorCode()<>0 Then
     Call TWAIN_ReportLastError("Unable to scan.")
End If