VintaSoft Twain .NET SDK Discussions
Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.
Board index < VintaSoft Twain < VintaSoft Twain .NET SDK Discussions
Private Shared Function ScanFromFlatbed(ByVal strFileName As String, Optional ByVal bShowSelectDevice As Boolean = True) As Boolean
If bShowSelectDevice AndAlso Not VSTwain1.SelectSource() Then
Return False
End If
MessageBox.Show("Place the " & IIf(ScanningMultiplePages, "first ", String.Empty) & "document on the scanning device then click OK to start scanning.", "Waiting for Document", MessageBoxButtons.OK, MessageBoxIcon.Information)
VSTwain1.ShowUI = False
VSTwain1.DisableAfterAcquire = True
VSTwain1.TransferMode = TransferMode.Native
VSTwain1.MaxImages = 1
VSTwain1.AutoCleanBuffer = True
VSTwain1.OpenDataSource()
DetectDeviceType()
SetCapabilities()
VSTwain1.XferCount = 1
VSTwain1.PdfDocumentInfo.Author = "MyApplicationNameHere"
VSTwain1.PdfDocumentInfo.Creator = "VintaSoftTWAIN.NET v" & VSTwain1.Version
VSTwain1.PdfImageCompression = PdfImageCompression.Auto
VSTwain1.PdfMultiPage = True
Dim bDoneScanning As Boolean = False
Dim bRescanning As Boolean = False
While Not bDoneScanning
If VSTwain1.AcquireModal() Then
Try
VSTwain1.SaveImage(0, strFileName)
Catch ex As TwainException
WriteToDebugFile(ex.ToString)
MessageBox.Show(ex.Message, "Scanning Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
If ScanningMultiplePages Then ' prompt the user to see if there are more pages left to scan
If MessageBox.Show("Do you have any more pages to append to this document?", "Multi-page Flatbed Scanning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
' we need to pause so the user can place the next original on the scanner
MessageBox.Show("Place the next document on the scanning device then click OK to continue.", "Waiting for Next Document", MessageBoxButtons.OK, MessageBoxIcon.Information)
bRescanning = True
Else
bDoneScanning = True
bRescanning = False
End If
Else
bDoneScanning = True
End If
ElseIf bRescanning Then ' ignore the acquire failure
bRescanning = False
Else
Return False
End If
End While
Return True
End Function
NOTE: The above code assumes the library has already been registered and that StartDevice() has already been called.ElseIf bRescanning Then ' ignore the acquire failure
bRescanning = False
Which I had to do because the next time AcquireModal() was called it would immediately return false and nothing would happen, but calling it again would result in another scan. This may be part of the problem, but I don't understand why that happens or what is going on when it does occur so any help would be appreciated....
If VSTwain1.AcquireModal() Then
...
End If
...
and here is correct code:
...
While VSTwain1.AcquireModal() Then
...
End While
...
About settings: You should set parameters of scanning for each session, i.e. you should set parameters after each OpenDataSource method.