Home | Download | Register | Testimonials | Support English version   Deutsche Version   Русская версия   Português versião   Española versión   Version française


VintaSoftTwain.NET Library    General information Info  License agreement License  FAQ FAQ  Examples Examples  History History  Download Download  Buy now Buy now



General questions:
  • For which purposes can I use the VintaSoftTwain.NET Library?
  • From which parts does the library consist?
  • In which programming languages can I use the VintaSoft.Twain component?
  • What restrictions does the unregistered version have?
  • I have problems. What should I do?

  • Redistribution:
  • What files do I need to include in the setup package of my program?
  • Can I re-distribute the VintaSoft.Twain.dll with my application without royalties?

  • Programming:
  • How can I add the VintaSoft.Twain component to a form in my .NET project?
  • How can I acquire black-white images?
  • How can I work with ADF without displaying the User Interface?
  • How can I work with ADF without displaying the User Interface and without the PostScan event?
  • I want to scan only a part of image. How can I do this?
  • How can I select a device without displaying the device selection dialog?
  • How can I disable the progress indicator dialog when I acquire images without UI?
  • I want to create my own progress indicator of image scan. Is this possible?
  • Can I set a different Resolution in the X and Y direction?
  • I want to scan documents in a separate thread. Is it possible?
  • Our organization has a network scanner with ADF and we scan many documents each day. How can we automate our work? We want to save each document in a separate file.
  • Can I use patch codes to separate batch jobs? If so, how can I detect the end of batch job?
  • I want to store acquired images in collection and then process them. How can I do this?
  • When I am using HP Scanjet scanner, I am losing the top 1/2 inch of the scan - and there is an extra 1/2 inch of black space at the bottom of the scan. How can I solve this problem?

  • Web deployment:
  • What steps should I make to add the VintaSoft.Twain Component to my web project?
  • I want to create a script on my website which would automatically configure .NET Framework security settings for my web server, allowing me to avoid complex configurations routines for the end user. What should I do?
  • I have a message "Your .NET Framework Security settings must be configured to run the components in your browser" when I run my web application. What did I make wrong?
  • I try to select device with the SourceIndex property in Internet Explorer but I get an error. Why?

  • Databases:
  • Can I store acquired images into a table of MS SQL server?


  •  
    For which purposes can I use the VintaSoftTwain.NET Library?
    The library can be used for controlling a work of scanners, web or digital cameras and any other TWAIN devices.


     
    From which parts does the library consist?
    The library contains:
  • VintaSoft.Twain component - a 100% .NET component (VintaSoft.Twain.dll file)
  • Documentation in CHM format (VintaSoft.Twain.chm file)
  • Examples for MS Visual Basic.NET, MS Visual C#, Borland Delphi 8.0, Borland C# Builder, ASP.NET (files in
  •     the Examples directory)


     
    In which programming languages can I use the VintaSoft.Twain component?
    With Single Developer license or Site license you can use component in:
  • Microsoft Visual Studio .NET : Visual Basic, Visual C#, Visual C++, Visual J#
  • Borland Delphi 8.0, Borland C# Builder, Borland C++ BuilderX
  • any other languages which are compatible with .NET Framework.

  • With Server license you can use component in:
  • Internet Explorer : ASP.NET, JavaScript, VBScript


  •  
    What restrictions does the unregistered version have?
    Unregistered version has the following restrictions:
  • nag screen
  • any image can be saved to a disk or uploaded onto server as BMP file
  • only black-white, gray or palette image can be saved to a disk or uploaded onto server as JPEG or TIFF file

  • All these restrictions are removed in registered version.


     
    I have problems. What should I do?
    The information on most of questions can be found in the documentation or in this FAQ.
    Write to our support team to get more help.


     
    What files do I need to include in the setup package of my program?
    You need include only one file: VintaSoft.Twain.dll. This file must be placed in the same folder as the assembly that references it. Make sure that the version you distribute is the version your assembly was compiled with.


     
    Can I re-distribute the VintaSoft.Twain.dll with my application without royalties?
    Yes, this component is royalty free. You pay only for registration one time. Only this componet can be re-distributed with your application.
    Single Developer license has limitation in re-distribution. Please see license agreement.


     
    How can I add the VintaSoft.Twain component to a form in my project?
    To add VintaSoft.Twain component to your form you should do the following:
  • Start Visual Studio.NET with your own project
  • Open the main form in design view
  • Open Toolbox pane
  • Right mouse click on the Toolbox pane
  • Select "Customize Toolbox..." menu item from popup menu
  • Open .NET Framework Components tab
  • Click "Browse..." and select VintaSoft.Twain.dll file
  • Find and check the VintaSoft.Twain component in the list
  • Close window using OK button
  • Find and select in the Toolbox pane VintaSoft.Twain item
  • Place the VintaSoft.Twain component on the form by selecting control rectangle


  •  
    How can I acquire black-white images?
    Here is a sample of code for acquiring only black-white images:
      Private Sub StartScan()
          VSTwain1.StartDevice
          If VSTwain1.SelectSource Then
              VSTwain1.OpenDataSource
              VSTwain1.PixelType = PixelType.BW
              VSTwain1.Acquire
          End If
      End Sub

     
    How can I work with ADF without displaying the User Interface?
    Here is a sample of code to drive a scanner with an ADF without the Data Source user interface:
      Private Sub StartScan()
          VSTwain1.StartDevice()
          VSTwain1.SelectSource()
          VSTwain1.ShowUI = false
          VSTwain1.DisableAfterAcquire = true
          VSTwain1.MaxImages = 1
          VSTwain1.AutoCleanBuffer = true
          VSTwain1.OpenDataSource()
          VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
          VSTwain1.PixelType = PixelType.RGB
          VSTwain1.Resolution = 200
          VSTwain1.TiffMultiPage = true
          VSTwain1.TiffCompression = TiffCompression.Auto
          If VSTwain1.Duplex <> DuplexMode.None Then
              VSTwain1.DuplexEnabled = true   ' enable Duplex
          End If
          If VSTwain1.FeederPresent Then
              VSTwain1.FeederEnabled = true
              VSTwain1.AutoFeed = true
              VSTwain1.XferCount = -1
              If VSTwain1.FeederLoaded Then
                  VSTwain1.Acquire()
              Endif
          Endif
      End Sub
    
      Private Sub VSTwain1_PostScan(ByVal sender As Object,
                                    ByVal e As VintaSoft.Twain.PostScanEventArgs)
                                    Handles VSTwain1.PostScan
          If Not e.Flag Then
              If VSTwain1.ErrorCode <> 0 Then
                  MsgBox VSTwain1.ErrorString
              End If
          Else
              If Not (VStwain1.SaveImage(0,"c:\test.tiff") Then
                  MsgBox VSTwain1.ErrorString
              End If
              If VSTwain1.DataSourceState = DataSourceState.Closed Then
                  VSTwain1.StopDevice()
                  MsgBox "Scan completed."
              Endif
          End If
      End Sub

     
    How can I work with ADF without displaying the User Interface and without the PostScan event?
    Here is a sample of code to drive a scanner with an ADF without the Data Source user interface:
      Private Sub StartScan()
          VSTwain1.StartDevice()
          VSTwain1.SelectSource()
          VSTwain1.ShowUI = false
          VSTwain1.DisableAfterAcquire = true
          VSTwain1.MaxImages = 1
          VSTwain1.AutoCleanBuffer = true
          VSTwain1.OpenDataSource()
          VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
          VSTwain1.PixelType = PixelType.RGB
          VSTwain1.Resolution = 200
          VSTwain1.TiffMultiPage = true
          VSTwain1.TiffCompression = TiffCompression.Auto
          If VSTwain1.Duplex <> DuplexMode.None Then
              VSTwain1.DuplexEnabled = true   ' enable Duplex
          End If
          If VSTwain1.FeederPresent Then
              VSTwain1.FeederEnabled = true
              VSTwain1.AutoFeed = true
              VSTwain1.XferCount = -1
              If VSTwain1.FeederLoaded Then
                  While VSTwain1.AcquireModal()
                      If Not VStwain1.SaveImage(0,"c:\test.tiff") Then
                          MsgBox VSTwain1.ErrorString
                      End If
                  End While
                  VSTwain1.StopDevice()
                  MsgBox "Scan completed."
              Endif
          Endif
      End Sub
    

     
    I want to scan only a part of image. How can I do this?
    You can use following code for acquiring only a part of image limited by rectangle (0.5,0.5) - (6,8):
      VSTwain1.StartDevice()
      VSTwain1.ShowUI = False
      VSTwain1.OpenDataSource()
      .............
      VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
      VSTwain1.SetImageLayout(0.5,0.5,6,8)
      VSTwain1.Acquire()
    

     
    How can I select a device without displaying the device selection dialog?
    You can use following code for enumerating your devices:
      VSTwain1.StartDevice
      For i = 0 To (VSTwain1.SourcesCount - 1)
         MsgBox VSTwain1.GetSourceProductName(i)
      Next
    
    And this code for select first device:
      VSTwain1.StartDevice
      VSTwain1.SourceIndex = 0
      .....
      VSTwain1.Acquire
    
    But the following way is the best:
      VSTwain1.StartDevice
      For i = 0 To (VSTwain1.SourcesCount - 1)
         If VSTwain1.GetSourceProductName(i) = "Your device name" Then
           VSTwain1.SourceIndex = i
           break
        End If
      Next
      .....
    
    In this case you must know correct device name.


     
    How can I disable the progress indicator dialog when I acquire images without UI?
    TWAIN standard allows to disable the progress indicator dialog when ShowUI=false. This can be made as follows:
      VSTwain1.StartDevice
      VSTwain1.ShowUI = false
      VSTwain1.DisableAfterAcquire = true
      VSTwain1.MaxImages = 1
      VSTwain1.OpenDataSource
      VSTwain1.ShowIndicators = 0
      VSTwain1.Acquire
    

     
    I want to create my own progress indicator of image scan. Is this possible?
    Yes, this is possible if you use a Memory transfer mode - you should use a Progress event. Here is an example:
      Private Sub VSTwain1_ImageProcessingProgress(ByVal sender As Object, _
                           ByVal e As VintaSoft.Twain.ProgressEventArgs) _
                           Handles VSTwain1.Progress
          If e.action = Action.Deskew Then
            txtAction.Text = "Deskewing..."
          ElseIf e.action = Action.Despecle Then
            txtAction.Text = "Despeckling..."
          ElseIf e.action = Action.BorderDetection Then
            txtAction.Text = "Border detecting..."
          ElseIf e.action = Action.Rotation Then
            txtAction.Text = "Rotating..."
          ElseIf e.action = Action.ImageScan Then
            txtAction.Text = "Image scan..."
          End If
          progressBar1.Value = e.percentComplete
          e.interrupt = bFinishFlag
      End Sub

     
    Can I set a different Resolution in the X and Y direction?
    Yes. Here is the sample of code how to set X Resolution to 4800 dpi and Y Resolution to 9600 dpi:
      VSTwain1.StartDevice
      VSTwain1.ShowUI = false
      VSTwain1.DisableAfterAcquire = true
      VSTwain1.MaxImages = 1
      VSTwain1.OpenDataSource
      VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
      VSTwain1.Capability = Capability.IXResolution
      VSTwain1.CapType = CapType.OneValue
      VSTwain1.CapValue = 4800     ' 4800 dpi
      VSTwain1.SetCap
      VSTwain1.Capability = Capability.IYResolution
      VSTwain1.CapType = CapType.OneValue
      VSTwain1.CapValue = 9600     ' 9600 dpi
      VSTwain1.SetCap
      VSTwain1.Acquire
    

     
    I want to scan documents in a separate thread. Is it possible?
    Yes, it is possible if the AcquireModal method will be used. Here is an example for C#:
      .....
      public class Form1 : System.Windows.Forms.Form
      {
        private VSTwain twain=null;
    
        .....
    
        private void buttonScanASync_Click(object sender, System.EventArgs e)
        {
          ThreadStart ts = new ThreadStart(this.doScanning);
          Thread t = new Thread(ts);
          t.Name = "Scan-Thread";
          t.Start();
        }
    
        private void doScanning()
        {
          twain = new VSTwain();
          if (twain.StartDevice())
          {
            twain.ShowUI = false;
            if (twain.SelectSource())
            {
              while (twain.AcquireModal())
              {
                pictureBox.Image = twain.GetCurrentImage();
              }
            }
            twain.StopDevice();
          }
        }
        .....
      }
      .....
    

     
    Our organization has a network scanner with ADF and we scan many documents each day. How can we automate our work? We want to save each document in a separate file.
    You can use blank page for separation of documents and detect blank page, as delimiter of documents, by the IsBlankPage method. Here is an example:
      Dim documentsCounter as Integer
    
      ............
      documentsCounter = 0
      ............
    
      Private Sub StartScan()
          VSTwain1.StartDevice()
          If VSTwain1.SelectSource() = 1 Then
              VSTwain1.ShowUI = false        
              VSTwain1.DisableAfterAcquire = true
              VSTwain1.MaxImages = 1
              VSTwain1.AutoCleanBuffer = true
              VSTwain1.TiffMultiPage = true          
              VSTwain1.TiffCompression = TiffCompression.Auto
              If VSTwain1.OpenDataSource() = 1 Then
                  VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
                  VSTwain1.PixelType = PixelType.GRAY
                  VSTwain1.Resolution = 200                    ' 200 dpi
                  If VSTwain1.Duplex <> DuplexMode.None Then
                      VSTwain1.DuplexEnabled = true   
                  End If
                  If VSTwain1.FeederPresent Then
                      VSTwain1.XferCount = -1
                      VSTwain1.FeederEnabled = true
                      VSTwain1.AutoFeed = true
                      If VSTwain1.FeederLoaded Then
                          VSTwain1.Acquire()
                      End If
                  End If
              End If
          End If
      End Sub
    
      Private Sub VSTwain1_PostScan(ByVal Flag As Long)
          If Flag <> 0 Then
              If VSTwain1.ErrorCode <> 0 Then
                  MsgBox VSTwain1.ErrorString
              End If
          Else
              ' check the first image (page)
              If VSTwain1.IsBlankImage(0) Then                 
                documentsCounter = documentsCounter + 1
              End If
              If Not VStwain1.SaveImage(0,"c:\documents\doc"+
                                        Str(documentsCounter)+".tiff") Then
                MsgBox VSTwain1.ErrorString
              End If
              If VSTwain1.DataSourceState = 0 Then
                  VSTwain1.StopDevice()
                  MsgBox "Scan completed."
              End if
          End If
      End Sub
    

     
    Can I use patch codes to separate batch jobs? If so, how can I detect the end of batch job?
    You can detect batch jobs by using the CAP_JOBCONTROL Capability.
    Here is an example for Visual Basic .NET:
      Dim jobsCounter As Integer
      
      Private Sub Form_Load()
        jobsCounter = -1
      End Sub
      
      Private Sub Scan_Click()
        VSTwain1.StartDevice
        VSTwain1.MaxImages = 1
        VSTwain1.ShowUI = false
        VSTwain1.DisableAfterAcquire = true
        VSTwain1.TiffMultiPage = true
        VSTwain1.OpenDataSource
        ' 1 - Detect and include job separator and continue scanning.
        ' 3 - Detect and exclude job separator and continue scanning.
        VSTwain1.JobControl = 1
        jobsCounter = jobsCounter + 1
        VSTwain1.Acquire
      End Sub
      
      Private Sub VSTwain1_PostScan(ByVal sender As System.Object,
               ByVal e As VintaSoft.Twain.PostScanEventArgs) Handles VSTwain1.PostScan
        If Not e.Flag Then
          If VSTwain1.ErrorCode <> 0 Then
            MsgBox(VSTwain1.ErrorString)
          End If
        Else
          If VSTwain1.EndOfJob Then
            jobsCounter = jobsCounter + 1
          Else
            VSTwain1.SaveImage 0, "c:\job"+jobsCounter.ToString()+".tif"
          End If
        End If
      End Sub
      .....
    

     
    I want to store acquired images in collection and then process them. How can I do this?
    If you want to store acquired images in your own buffer (for example in Collection object in VB.NET), then you must create a full copy of image object returned by the GetImage method, and place it to your buffer. You cannot place to the buffer an image object returned by the GetImage method because this object will be destroyed when you will acquire new image or when you will call the StopDevice method.

    Here is correct code:
      ...
      Dim colDocumentPages As New Collection
      ...
      Dim picNewPage As Image = New Bitmap(vnsScanner.GetCurrentImage)
      colDocumentPages.Add(picNewPage)
      ...
    
    And here is not correct code:
      ...
      Dim colDocumentPages As New Collection
      ...
      Dim picNewPage As Image
      picNewPage = vnsScanner.GetCurrentImage
      colDocumentPages.Add(picNewPage)
      ...
    

     
    When I am using HP Scanjet scanner, I am losing the top 1/2 inch of the scan - and there is an extra 1/2 inch of black space at the bottom of the scan. How can I solve this problem?
    You should switch value of the PageSize property from A4 to USLETTER and this will solve the problem.


     
    What steps should I make to add the VintaSoft.Twain Component to my web project?
    On Server side you must do the following:
    1. Place the VintaSoft.Twain assembly (VintaSoft.Twain.dll file) on to the server.
    2. Use the following code in your web page:
        <OBJECT ID="VSTwain1" WIDTH=1 HEIGHT=1 
                CLASSID="http://your-server/path-on-server/
                         VintaSoft.Twain.dll#VintaSoft.Twain.VSTwain" CODEBASE="http://your-server/path-on-server/
                          VintaSoft.Twain.dll#version=3,1,0,1"> </OBJECT>
      Correct number of version is very important. With wrong version number your customers will download the assembly each time when they will open your web page.
    3. The subfolder where you plan to store images must be granted write privileges to Everyone.

    On Client side you must do the following:
    1. .NET Framework 1.0 or greater must be installed.
    2. Internet Explorer 6.0 or greater must be used.
    3. The .NET Security policy must be set to the your web site.
      You can do this as follows:
      1. Open the Microsoft .NET Framework Configuration from Control Panel | Administrative Tools
      2. Select Runtime Security Policy | Machine | Code Groups | All_Code
      3. Right click All_Code and select New to create a new code group
      4. Name the code group My_Web_Site
      5. Choose the Site condition for the code group
      6. Set the Site name as my_web_site.com
      7. Assign a Permission Set to the Code Group as Full Trust
      For more information on .NET security policies, please read this MSDN article.


     
    I want to create a script on my website which would automatically configure .NET Framework security settings for my web server, allowing me to avoid complex configurations routines for the end user. What should I do?
    You can create a script which will execute this command:

        caspol.exe -q -machine -addgroup All_Code -site www.my-company.com FullTrust
                        -name VSTwain_MyCompany_Site
                        -description "This permission set grants the right to use VSTwain object on www.my-company.com."


     
    I have a message "Your .NET Framework Security settings must be configured to run the components in your browser" when I run my web application. What did I make wrong?
    First of all you should set a .NET Framework policy as described here.
    Next you should check which version of VintaSoft.Twain.dll you use (for example, 3.1.0.1).
    Further you should set an OBJECT object in your web page correctly. Correct version number is very important!
    Here is an example:

      <OBJECT ID="VSTwain1" WIDTH=1 HEIGHT=1
                     CLASSID="http://your-server/path-on-server/VintaSoft.Twain.dll#VintaSoft.Twain.VSTwain"
                     CODEBASE="http://your-server/path-on-server/VintaSoft.Twain.dll#version=3,1,0,1">
      </OBJECT>

    It's all that you should do.


     
    I try to select device with the SourceIndex property in Internet Explorer but I get an error. Why?
    Each object of web page in Internet Explorer has a SourceIndex property. This is a read-only property. You must use the following code to work with a SourceIndex property of a VSTwain object in JavaScript or VBScript:

      VSTwain1.StartDevice()
      VSTwain1.object.SourceIndex = 1   ' second device
      VSTwain1.Acquire()
    

     
    Can I store acquired images into a table of MS SQL server?
    Yes, you can do this, please see example 3 here.




    Copyright © 2008 VintaSoft Ltd. All rights reserved.