SCANNING MULTIPLE DOCUMENTS.

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
amejiae
Posts: 3
Joined: Thu Aug 26, 2010 12:37 pm

SCANNING MULTIPLE DOCUMENTS.

Post by amejiae » Thu Aug 26, 2010 12:41 pm

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

Yuri
Posts: 56
Joined: Wed Jul 23, 2008 2:47 pm

Re: SCANNING MULTIPLE DOCUMENTS.

Post by Yuri » Thu Aug 26, 2010 12:53 pm

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

amejiae
Posts: 3
Joined: Thu Aug 26, 2010 12:37 pm

Re: SCANNING MULTIPLE DOCUMENTS.

Post by amejiae » Thu Aug 26, 2010 1:24 pm

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?

Yuri
Posts: 56
Joined: Wed Jul 23, 2008 2:47 pm

Re: SCANNING MULTIPLE DOCUMENTS.

Post by Yuri » Thu Aug 26, 2010 2:45 pm

You can find the example code in the documentation provided with version 6.0.

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

Regards

Alex
Site Admin
Posts: 1445
Joined: Thu Jul 10, 2008 2:21 pm

Re: SCANNING MULTIPLE DOCUMENTS.

Post by Alex » Mon Aug 30, 2010 1:41 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest