Product Info
Testimonials |
VintaSoftTwain.NET SDK - FAQGeneral questions:
Redistribution:
Deployment:
Programming:
Web:
Databases:
For which purposes can I use the VintaSoftTwain.NET SDK?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:
In which programming languages can I use the Vintasoft.Twain component?With Single Developer license or Site license you can use component in:
With Server license you can use component in:
What restrictions does the unregistered version have?Unregistered version has the following restrictions:
All these restrictions are removed in registered version.
I have problems. What should I do?Answers to most of questions can be found in the documentation or in this FAQ. Please 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 Vintasoft.Twain.dll can be re-distributed with your application.
Can I use VintaSoftTwain.NET SDK in 64-bit version of Windows?Yes, you can use VintaSoftTwain.NET SDK in 64-bit version of Windows. Here is a list of steps that you should do:
How can I add the VintaSoft.Twain component to a form in my .NET project?To add VintaSoft.Twain component to your form you should do the following:
How can I acquire black-white images?Here is a sample of code for acquiring black-white images only:
Private Sub StartScan()
Try
VSTwain1.StartDevice()
If VSTwain1.SelectSource() Then
VSTwain1.OpenDataSource()
VSTwain1.PixelType = PixelType.BW
VSTwain1.Acquire()
End If
Catch ex As TwainException
MsgBox(ex.Message)
End Try
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 StartScanButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles StartScanButton.Click
Try
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
End If
If VSTwain1.FeederPresent Then
VSTwain1.FeederEnabled = true
VSTwain1.AutoFeed = true
VSTwain1.XferCount = -1
If VSTwain1.FeederLoaded Then
VSTwain1.Acquire()
Endif
Endif
Catch ex As TwainException
MsgBox(ex.Message)
End Try
End Sub
Private Sub VSTwain1_ImageAcquired(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ImageAcquired
Try
VStwain1.SaveImage(0,"c:\test.tiff")
Catch ex As ImagingException
MsgBox(ex.Message)
End Try
End Sub
Private Sub VSTwain1_ScanCompleted(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ScanCompleted
If VSTwain1.ErrorCode <> ErrorCode.None Then
MsgBox(VSTwain1.ErrorString)
Else
MsgBox("Scan process is completed.")
End If
End Sub
Can I hide the user interface and acquire images in modal loop?Here is a sample of code to drive a scanner with an ADF without the Data Source user interface:
Private Sub StartScanButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles StartScanButton.Click
Try
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()
Try
VStwain1.SaveImage(0,"c:\test.tiff")
Catch ex As TwainException
MsgBox(ex.Message)
End Try
End While
VSTwain1.StopDevice()
MsgBox "Scan completed."
Endif
Endif
Catch ex As TwainException
MsgBox(ex.Message)
End Try
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
sourceInfo = VSTwain1.GetSourceInfo(i)
If sourceInfo.IsTwain2Compatible Then
MsgBox "Device " + sourceInfo.ProductName + _
" is TWAIN 2.0 compatible."
Else
MsgBox "Device " + sourceInfo.ProductName + _
" is not TWAIN 2.0 compatible."
End If
Next
And this code for select first device:
VSTwain1.StartDevice() VSTwain1.SourceIndex = 0 ..... VSTwain1.AcquireBut 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
Select Case e.Action
Case Action.Deskew
txtAction.Text = "Deskewing..."
Case Action.Despecle
txtAction.Text = "Despeckling..."
Case Action.BorderDetection
txtAction.Text = "Border detecting..."
Case Action.Rotation
txtAction.Text = "Rotating..."
Case Action.ImageScan
txtAction.Text = "Image scan..."
Case Action.ImageSaving
txtAction.Text = "Saving image to PDF document..."
End Select
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();
try
{
twain.StartDevice();
twain.ShowUI = false;
if (twain.SelectSource())
{
while (twain.AcquireModal())
{
pictureBox.Image = twain.GetCurrentImage();
}
}
twain.StopDevice();
}
catch (TwainException ex)
{
MessageBox.Show(ex.Message);
}
}
.....
}
.....
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()
Try
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
VSTwain1.OpenDataSource()
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
Catch ex As TwainException
MsgBox(ex.Message)
End Try
End Sub
Private Sub VSTwain1_ImageAcquired(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ImageAcquired
If VSTwain1.IsBlankImage(0) Then ' check the first image (page)
documentsCounter = documentsCounter + 1
End If
Try
VStwain1.SaveImage(0,"c:\documents\doc"+Str(documentsCounter)+".pdf")
Catch ex As PdfException
MsgBox(ex.Message)
End Try
End Sub
Private Sub VSTwain1_ScanCompleted(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ScanCompleted
If VSTwain1.ErrorCode <> ErrorCode.None Then
MsgBox(VSTwain1.ErrorString)
Else
MsgBox("Scan process is completed.")
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.
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_ImageAcquired(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ImageAcquired
If VSTwain1.EndOfJob Then
jobsCounter = jobsCounter + 1
Else
VSTwain1.SaveImage 0, "c:\job"+jobsCounter.ToString()+".tif"
End If
End Sub
Private Sub VSTwain1_ScanCompleted(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles VSTwain1.ScanCompleted
If VSTwain1.ErrorCode <> ErrorCode.None Then
MsgBox(VSTwain1.ErrorString)
Else
MsgBox("Scan process is completed.")
End If
End Sub
.....
I want to store acquired images in collection and then process them. How can I do this?GetImage/GetCurrentImage methods return a new Bitmap object so you can use it in your collection: ... Dim colDocumentPages As New Collection ... Dim picNewPage As Image = vnsScanner.GetCurrentImage() colDocumentPages.Add(picNewPage) ...
Can I save acquired images to PDF document?Yes, you can do this. Acquired images can be saved to a new PDF document or added to an existing PDF document.
VSTwain1.PdfDocumentInfo.Author = "VintaSoft Ltd."
VSTwain1.PdfDocumentInfo.Title = "Documents acquired from " + _
VSTwain1.GetSourceProductName(VSTwain1.SourceIndex)
VSTwain1.PdfDocumentInfo.Creator = "VintaSoftTwain.NET SDK"
VSTwain1.PdfDocumentInfo.ModificationDate = DateTime.Now
VSTwain1.PdfMultiPage = true
VSTwain1.SaveImage(0, "c:\test.pdf")
How can I retrieve an extended image info from the scanner?This example demonstrates how to get information about barcodes found on acquired image:
Public Sub ScanWithoutUI()
VSTwain1.AppProductName = "MyTwainApplication"
Try
VSTwain1.StartDevice()
VSTwain1.SelectSource()
VSTwain1.ShowUI = false
VSTwain1.ExtendedImageInfoCollection.Add(New _
ExtendedImageInfo(ExtendedImageInfoId.BarcodeCount))
VSTwain1.ExtendedImageInfoCollection.Add(New _
ExtendedImageInfo(ExtendedImageInfoId.BarcodeType))
VSTwain1.ExtendedImageInfoCollection.Add(New _
ExtendedImageInfo(ExtendedImageInfoId.BarcodeTextLength))
VSTwain1.ExtendedImageInfoCollection.Add(New _
ExtendedImageInfo(ExtendedImageInfoId.BarcodeText))
While VSTwain1.AcquireModal()
If Not (PictureBox1.Image Is Nothing) Then
PictureBox1.Image.Dispose()
PictureBox1.Image = Nothing
End If
PictureBox1.Image = VSTwain1.GetCurrentImage
VSTwain1.SaveImage 0, "c:\test.tiff"
' retrieve extended image info
Dim barcodeCount As ExtendedImageInfo = _
VSTwain1.ExtendedImageInfoCollection(0)
If barcodeCount.Items IsNot Nothing And barcodeCount.Items.Length > 0 Then
If barcodeCount.Items(0) > 0 Then
Dim barcodeType As ExtendedImageInfo = _
VSTwain1.ExtendedImageInfoCollection(1)
Dim barcodeTextLength As ExtendedImageInfo = _
VSTwain1.ExtendedImageInfoCollection(2)
Dim barcodeText As ExtendedImageInfo = _
VSTwain1.ExtendedImageInfoCollection(3)
Dim i As Integer, infoString As String
For i = 0 To barcodeCount.Items(0) - 1
infoString = ""
If barcodeType.IsValid Then
infoString = "BarcodeType=" + barcodeType.Items(i) + " "
Else
infoString = "BarcodeType=Undefined "
End If
If barcodeText.IsValid Then
infoString = "BarcodeText='" + barcodeText.Items(i) + "'"
Else
infoString = "BarcodeText=Undefined "
End If
MsgBox(infoString)
Next i
End If
End If
End While
Catch ex As TwainException
MsgBox ex.Message
Catch ex As ImagingException
MsgBox ex.Message
End Try
End Sub
Can I acquire 48-bit images?Yes. VintaSoftTwain.NET SDK allows to acquire 48-bit color images or 16-bit gray images. Images can be saved without loss of bit depth only in TIFF files. VSTwain1.OpenDataSource() VSTwain1.PixelType = PixelType.RGB VSTwain1.Capability = DeviceCapability.IBitDepth VSTwain1.CapType = CapType.OneValue VSTwain1.CapValue = 16 ' 16 bits per color component VSTwain1.SetCap() VSTwain1.Acquire() Here is an example that demonstrates how to acquire 24-bpp color image without UI from scanner: VSTwain1.OpenDataSource() VSTwain1.PixelType = PixelType.RGB VSTwain1.Capability = DeviceCapability.IBitDepth VSTwain1.CapType = CapType.OneValue VSTwain1.CapValue = 8 ' 8 bits per color component VSTwain1.SetCap() VSTwain1.Acquire() Here is an example that demonstrates how to acquire 16-bpp gray image without UI from scanner: VSTwain1.OpenDataSource() VSTwain1.PixelType = PixelType.Gray VSTwain1.Capability = DeviceCapability.IBitDepth VSTwain1.CapType = CapType.OneValue VSTwain1.CapValue = 16 ' 16 bits per color component VSTwain1.SetCap() VSTwain1.Acquire()
Can I create predefined session setup for my high-volume scanner?Yes, library allows to load/save predefined session setups for mid- and high-volume scanners.
VSTwain1.OpenDataSource()
Dim fs As FileStream = New FileStream("scanner-setup.xml", FileMode.Append, FileAccess.Write)
VSTwain1.SaveDeviceSettings(fs)
fs.Close()
Here is an example that demonstrates how to load previously saved device settings into the device:
VSTwain1.OpenDataSource()
Dim fs As FileStream = New FileStream("scanner-setup.xml", FileMode.Open, FileAccess.Read)
VSTwain1.LoadDeviceSettings(fs)
fs.Close()
VSTwain1.Acquire()
What steps should I make to add the VintaSoft.Twain Component to my web project?On Server side you must do the following:
< OBJECT ID="VSTwain1" WIDTH=1 HEIGHT=1 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. On Client side you must do the following:
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
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, 5.0.5.3). 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 It's all that you should do.
I'm trying 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 scan images and upload them to the server in intranet application with integrated windows authentication?Yes, library allows to use any authentication methods supported by .NET Framework. The following example illustrates how to use authentication information of the currently logged on user: ... httpUpload1.Url = "http://localhost/vstwaindemo/imageupload.aspx" httpUpload1.UseDefaultCredentials = true ... The following example illustrates how to use multiple authentication information:
...
Dim myCache As New CredentialCache()
myCache.Add(New Uri("http://www.my-web-server.com/"), "Basic",
New NetworkCredential(UserName, SecurelyStoredPassword))
myCache.Add(New Uri("http://www.my-web-server.com/"), "Digest",
New NetworkCredential(UserName, SecurelyStoredPassword, Domain))
httpUpload1.Credentials = myCache
...
Can I scan images and upload them to the server in web application with Cookieless Forms authentication?Yes, you can do this, please see example 8 and 9 here.
Can I store acquired images into a table of MS SQL server?Yes, you can do this, please see example 3 here.
I want to store acquired images as PDF documents in database. Can I do this?Yes, you can save acquired image(s) to a stream and further save stream data to database. Here is an example that shows how to save each acquired image as a separate PDF document in a stream: Dim mem As MemoryStream = VSTwain1.GetImageAsStream(0, ImageFileFormat.PDF) And here is an example that shows how to save all acquired images as a single PDF document in a stream:
Dim mem As MemoryStream = VSTwain1.GetImageAsStream(0, ImageFileFormat.PDF)
Dim i As Integer
For i = 1 To VSTwain1.NumImages - 1
VSTwain1.SaveImageToStream(i, mem, ImageFileFormat.PDF)
Next i
|