Private VSTwain1 As New VintaSoftTwain()
''' <summary>
''' Scans images asynchronously.
''' </summary>
Private Sub StartScan()
' open the device manager
If Not VSTwain1.DeviceManager_Open() Then
Console.WriteLine(VSTwain1.errorString)
Exit Sub
End If
' select device using standard device selection dialog
VSTwain1.DeviceManager_ShowDefaultDeviceSelectionDialog()
' open the device
If Not VSTwain1.Device_Open() Then
Console.WriteLine(VSTwain1.errorString)
Exit Sub
End If
' specify that device UI must be shown
VSTwain1.Device_ShowUI = True
' set settings of PDF encoder
VSTwain1.PdfEncoder_MultiPage = True
VSTwain1.PdfEncoder_DocumentAuthor = "VintaSoft LLC."
Dim deviceName As String = VSTwain1.Device_Info_GetProductName(VSTwain1.DeviceManager_SelectedDeviceIndex)
VSTwain1.PdfEncoder_DocumentTitle = String.Format("Documents acquired from {0}", deviceName)
VSTwain1.PdfEncoder_DocumentCreator = "VintaSoft Twain ActiveX"
VSTwain1.PdfEncoder_DocumentModificationDate = DateTime.Now
' subscribe to the device events
AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired
AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted
AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed
AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled
' acquire images asynchronously
VSTwain1.Device_AcquireImage()
End Sub
Private Sub VSTwain1_ImageAcquired()
' get index of acquired image
Dim imageIndex As Integer = VSTwain1.AcquiredImages_Count - 1
' save acquired image to a PDF document
If Not VSTwain1.AcquiredImages_Save(imageIndex, "test.pdf") Then
Console.WriteLine(VSTwain1.errorString)
End If
End Sub
Private Sub VSTwain1_ScanCompleted()
Console.WriteLine("Scan is completed.")
End Sub
Private Sub VSTwain1_ScanFailed(errorString As String)
Console.WriteLine(String.Format("Scan is failed: {0}.", errorString))
End Sub
Private Sub VSTwain1_ScanCanceled()
Console.WriteLine("Scan is canceled.")
End Sub