VintaSoft Twain .NET SDK Discussions

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

Board index < VintaSoft Twain < VintaSoft Twain .NET SDK Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

SCANNING MULTIPLE DOCUMENTS.



SCANNING MULTIPLE DOCUMENTS.

Post 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.
 While TwainSource.AcquireModal()
                    Debug.Print("Scanned an image")
                    GetImage(TwainSource)
 End While
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.

Post by Yuri »

This example shows how to acquire images in modal loop from scanner with user interface and save acquired images to PDF document:
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.

Post 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.

Post 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.

Post 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: https://www.vintasoft.com/forums/viewtopic.php?f=19&t=3

Best regards, Alexander


Page 1 from 1: 1