ADF - Multiple 2 sided to multiple PDFs

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
rcsingle
Posts: 10
Joined: Tue Jan 12, 2010 11:37 pm

ADF - Multiple 2 sided to multiple PDFs

Post by rcsingle » Wed Jan 13, 2010 3:42 pm

I am evaluating your .Net product, version 6.5 for a VB.Net app.

Following your Twain examples I am able to scan multiple two sided documents from the ADF to one PDF file, or multiple single sided documents each to a separate PDF file, but I can't seem to find a way to scan multiple two sided document from the ADF each to a separate PDF file. Any ideas?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: ADF - Multiple 2 sided to multiple PDFs

Post by Loïc » Fri Jan 15, 2010 4:05 pm

Hi,

Just starts 2 PDF before your scan process:

Code: Select all

PdfID = oGdPictureImaging.TwainPdfStart("output.pdf", True, "", "", "", "", "")
PdfID2 = oGdPictureImaging.TwainPdfStart("output.pdf", True, "", "", "", "", "")

Then, you will be able to affect the current image to the desired PDF.

IE:

Code: Select all

Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
...
Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID2, ImageID)

And don't forget to release the two created PDFs:

Code: Select all

oGdPictureImaging.TwainPdfStop(PdfID)
oGdPictureImaging.TwainPdfStop(PdfID2)
Hope this helps.

With best regards,

Loïc Carrère

rcsingle
Posts: 10
Joined: Tue Jan 12, 2010 11:37 pm

Re: ADF - Multiple 2 sided to multiple PDFs

Post by rcsingle » Mon Jan 18, 2010 4:14 pm

Thank you, but I may have worded this wrong.

I need to scan a stack of 2 sided documents, with both sides of each document going to one file. So if I have 10 documents to scan, I end up with 10 files, each containing the 2 sides of one scanned document.

Thank you again for your help.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: ADF - Multiple 2 sided to multiple PDFs

Post by Loïc » Tue Jan 19, 2010 12:47 pm

Hi,

This kind of sample should work:

Code: Select all

       Dim ImageID As Integer
        Dim NumPDF As Integer = 0

        If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
            oGdPictureImaging.TwainSetHideUI(True)
            oGdPictureImaging.TwainEnableDuplex(True)

            oGdPictureImaging.TwainSetAutoFeed(True) 'Set AutoFeed Enabled
            oGdPictureImaging.TwainSetAutoScan(True) 'To  achieve the maximum scanning rate
            oGdPictureImaging.TwainSetResolution(200)
            oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_BW) 'Black & White
            oGdPictureImaging.TwainSetBitDepth(1) ' 1 bpp


            Do
                NumPDF += 1
                Dim PdfID As Integer = oGdPictureImaging.TwainPdfStart("output" & Trim(Str(NumPDF)) & ".pdf", True, "", "", "", "", "")
                'front
                ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                If ImageID <> 0 Then
                    Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
                    oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                End If

                'back
                ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                If ImageID <> 0 Then
                    Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
                    oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                End If

                oGdPictureImaging.TwainPdfStop(PdfID)
            Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED


            Call oGdPictureImaging.TwainCloseSource()
            MsgBox("Done !")
        Else
            MsgBox("can't open default source, twain state is: " & oGdPictureImaging.TwainGetState.ToString)
        End If
With best regards,

Loïc

rcsingle
Posts: 10
Joined: Tue Jan 12, 2010 11:37 pm

Re: ADF - Multiple 2 sided to multiple PDFs

Post by rcsingle » Tue Jan 19, 2010 5:02 pm

Loïc,

Thank you, that works great.

Randy

rcsingle
Posts: 10
Joined: Tue Jan 12, 2010 11:37 pm

Re: ADF - Multiple 2 sided to multiple PDFs

Post by rcsingle » Tue Jan 26, 2010 5:01 pm

Well it works great once during my application session. I am opening a form as a dialog from another form to do the scanning. The first time I open the form and scan, it works great. But once I close the scanning dialog form and open it again, then run the scan, it locks up on the "ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)" line of code. My project is in VS 2008. Any ideas why it is locking up?

These definitions are at the top of my class:

Code: Select all

  Dim oGdPictureImaging As New GdPictureImaging
  Dim ImageID As Integer

Here is the code:

    Private Sub ScanTest()
        Dim NumPDF As Integer = 0
        Dim PdfID As Integer = 0
        Dim count As Integer = 0

        Try
            If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
                InitScanConfig()
                GdViewer1.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer

                oGdPictureImaging.TwainEnableDuplex(True)

                Do
                    NumPDF += 1
                    PdfID = oGdPictureImaging.TwainPdfStart(strScannedFilesPath & "output" & Trim(Str(NumPDF)) & ".pdf", True, "", "", "", "", "")
                    'front
                    ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                    If ImageID <> 0 Then
                        Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
                        Call oGdPictureImaging.SaveAsJPEG(ImageID, strScannedFilesPath & "output" & Trim(Str(NumPDF)) & ".jpg", 90)
                        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                    End If

                    'back
                    ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                    If ImageID <> 0 Then
                        Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
                        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                    End If

                    oGdPictureImaging.TwainPdfStop(PdfID)
                    CloseCurrentImage()
                    Call DisplayImage(strScannedFilesPath & "output" & Trim(Str(NumPDF)) & ".pdf")

                Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED

                Call oGdPictureImaging.TwainCloseSource()

            Else
            oGdPictureImaging.TwainSelectSource(Me.Handle)
            End If

        Catch ex As Exception
            ExceptionHandler(ex, "frmScanDocs_ScanCQs")
        End Try

    End Sub

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: ADF - Multiple 2 sided to multiple PDFs

Post by Loïc » Tue Jan 26, 2010 5:40 pm

Hi,

maybe you should try to unload the source manager when the scan process is done.
This can be done adding:

Code: Select all

Call oGdPictureImaging.TwainUnloadSourceManager(Me.Handle)
just after:

Code: Select all

Call oGdPictureImaging.TwainCloseSource()
If your problem persists, please create a new TWAIN issue thread as as explained here: viewtopic.php?t=1486

With best regards,

Loïc

rcsingle
Posts: 10
Joined: Tue Jan 12, 2010 11:37 pm

Re: ADF - Multiple 2 sided to multiple PDFs

Post by rcsingle » Tue Jan 26, 2010 9:46 pm

Loïc,

Great, that worked!

Thank you,
Randy

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: ADF - Multiple 2 sided to multiple PDFs

Post by Loïc » Tue Jan 26, 2010 9:47 pm

Good news Randy !

Thank you for the feedback.

Cheers,

Loïc

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest