I tried to read some previous cases regarding this but I have not been able to get useful information.
I am trying to scan multiple documents but when the scanner finish only the last page is saved.
Private Sub GetImage(ByVal TwainSource As VSTwain)
Dim noiseLevel As Single
If TwainSource.IsBlankImage(0, 1.0, noiseLevel) Then
Debug.Print("Blank page detected")
' Me.Jobs.Add(Me.CurrentJob)
RaiseEvent JobComplete(Me.CurrentJob)
Me.CurrentJob = New Scanjob(LoggedInUser)
Else
Dim img As New Bitmap(TwainSource.GetImage(0))
Dim sc As ScannedImage = Me.CurrentJob.AddImage(img, Date.Now.Ticks.ToString & ".tiff")
RaiseEvent NewDocumentScanned(sc)
End If
Debug.Print("Noise level: " & noiseLevel.ToString())
End Sub
Friend Shared Sub Main(args As String())
Try
Using deviceManager As New DeviceManager()
' open the device manager
deviceManager.Open()
' get reference to the current device
Dim device As Device = deviceManager.Devices.Current
' open the device
device.Open()
' set acquisition parameters
device.TransferMode = TransferMode.Memory
device.ShowUI = False
device.DisableAfterAcquire = True
device.PixelType = PixelType.BW
' create directory for PDF document
Dim directoryForImages As String = Path.GetDirectoryName(Directory.GetCurrentDirectory())
directoryForImages = Path.Combine(directoryForImages, "Images")
If Not Directory.Exists(directoryForImages) Then
Directory.CreateDirectory(directoryForImages)
End If
Dim pdfFilename As String = Path.Combine(directoryForImages, "multipage.pdf")
' acquire image(s) from the device
Dim acquireModalState1 As AcquireModalState = AcquireModalState.None
Dim imageIndex As Integer = 0
Do
acquireModalState1 = device.AcquireModal()
Select Case acquireModalState1
Case AcquireModalState.ImageAcquired
' save image to file
device.AcquiredImages.Last.Save(pdfFilename)
' output current state
imageIndex = imageIndex + 1
Console.WriteLine(String.Format("Image{0} is saved.", imageIndex))
Case AcquireModalState.ScanCompleted
' close device and device manager
CloseDeviceAndDeviceManager(deviceManager, device)
' output current state
Console.WriteLine("Scan completed.")
Case AcquireModalState.ScanCanceled
' close device and device manager
CloseDeviceAndDeviceManager(deviceManager, device)
' output current state
Console.WriteLine("Scan canceled.")
Case AcquireModalState.ScanFailed
' close device and device manager
CloseDeviceAndDeviceManager(deviceManager, device)
' output current state
Console.WriteLine(String.Format("Scan failed: {0}", deviceManager.ErrorString))
End Select
Loop While acquireModalState1 <> AcquireModalState.None
End Using
Catch ex As TwainException
Console.WriteLine("Error: " + ex.Message)
End Try
Console.ReadLine()
End Sub
' Close device and device manager.
Private Shared Sub CloseDeviceAndDeviceManager(deviceManager As DeviceManager, device As Device)
If device.State = DeviceState.Opened Then
' close the device
device.Close()
End If
' close the device manager
deviceManager.Close()
End Sub
I am using version 6.0.0.1. Some properties in that code snippet are not available in version 6. Is there a way to do multiple scanning in version 6? maybe another code snipeet for version 6?
What scanner do you have? Some of Brother and Visioneer scanners returns only the last image if UI is not used - it's a known issue.
Please read this topic: viewtopic.php?f=19&t=3