Page 1 of 1

SCANNING MULTIPLE DOCUMENTS.

Posted: Thu Aug 26, 2010 12:41 pm
by amejiae
hI,

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.

Somehow my code looks like this.

Code: Select all

 While TwainSource.AcquireModal()
                    Debug.Print("Scanned an image")
                    GetImage(TwainSource)
 End While

Code: Select all

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
Any help is appreciated on this case.
Alejandro

Re: SCANNING MULTIPLE DOCUMENTS.

Posted: Thu Aug 26, 2010 12:53 pm
by Yuri
This example shows how to acquire images in modal loop from scanner with user interface and save acquired images to PDF document:

Code: Select all

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

Re: SCANNING MULTIPLE DOCUMENTS.

Posted: Thu Aug 26, 2010 1:24 pm
by amejiae
Hi

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?

Re: SCANNING MULTIPLE DOCUMENTS.

Posted: Thu Aug 26, 2010 2:45 pm
by Yuri
You can find the example code in the documentation provided with version 6.0.

Look at Vintasoft.Twain Namespace > VSTwain Class : AcquireModal Method

Regards

Re: SCANNING MULTIPLE DOCUMENTS.

Posted: Mon Aug 30, 2010 1:41 pm
by Alex
Hello Alejandro,

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

Best regards, Alexander