CreateImageFromTwain not working

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
steve888
Posts: 7
Joined: Wed Oct 14, 2009 9:42 pm

CreateImageFromTwain not working

Post by steve888 » Mon Oct 19, 2009 3:38 pm

I have taken the sample code found on this website and in the GdTwain Pro 2 Reference Guide in order to scan pages of a document feeder to a multipage searchable PDF file and get an error message. The VB code is as follows:

Code: Select all

    Twain1.TwainOpenDefaultSource
    Twain1.TwainSetAutoFeed (True)
    Twain1.TwainSetAutoScan (True)
    If Twain1.TwainPdfOCRStartEx("H:\GdTwainTests\mypdf.pdf") = 0 Then
        While Twain1.CreateImageFromTwain(Me.Hwnd) <> 0
            Call Twain1.TwainAddGdPictureImageToPdfOCR(Twain1.GetNativeImage, TesseractDictionaryEnglish, "C:\Program Files\GdTwain Pro ActiveX\redist\optional\ocrdata")
          Twain1.CloseNativeImage
        Wend
        Twain1.TwainPdfOCRStop
    End If
    Twain1.TwainCloseSource

When attempting to run this I get an error message on the line which contains the CreateImageFromTwain method:
Microsoft Visual Basic Run-time error '438': Object doesn't support this property or method.

Also, I cannot find this method in the Reference Guide, yet it is included in the Reference as sample code.

The goal here is to create a searchable PDF file from a scanned single or multi-page document. I am using GdTwain Pro ActiveX since according to the specifications I would be able to do this. I have also included the Twain1.SetLicenseNumberOCRTesseract statement when opening my form. Any assistance would be appreciated.

Sincerely,
Steve

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

Re: CreateImageFromTwain not working

Post by Loïc » Tue Oct 20, 2009 10:42 am

Hi Steve,

Please use the TwainAcquireToGdPictureImage() method instead. Sorry for the confusion. We will update reference guides.

Kind regards,

Loïc

steve888
Posts: 7
Joined: Wed Oct 14, 2009 9:42 pm

Re: CreateImageFromTwain not working

Post by steve888 » Tue Oct 20, 2009 4:12 pm

Hi Loic,

I modified the method as you suggested and that step is now working. It took me one line down in the code until I hit another run-time error (''5': Invalid procedure call or argument) on the line which contains TwainAddGdPictureImageToPdfOCR. The code which I used and modified for my requirements, taken from the TwainAddGdPictureImageToPdfOCR method Visual Basic sample code in the Reference Guide is:

Code: Select all

    Twain1.TwainOpenDefaultSource
    Twain1.TwainSetAutoFeed (True)
    Twain1.TwainSetAutoScan (True)
    If Twain1.TwainPdfOCRStartEx("H:\GdTwainTests\mypdf.pdf") = 0 Then
        While Twain1.TwainAcquireToGdPictureImage(Me.Hwnd) <> 0
            Call Twain1.TwainAddGdPictureImageToPdfOCR(Twain1.GetNativeImage, TesseractDictionaryEnglish, "C:\Program Files\GdTwain Pro ActiveX\redist\optional\ocrdata")
          Twain1.CloseNativeImage
        Wend
        Twain1.TwainPdfOCRStop
    End If
    Twain1.TwainCloseSource
Before hitting the run-time error the program opens a TWAIN dialog box. When I hit the New Scan button the scanning process begins. After the scanning is completed I click the Accept button. It is at this point that the error message appears. Should I be getting this dialog box?

In addition to fixing this error I want to know if there is a way to avoid having this dialog box appear.

Thanks for your help.

Sincerely,
Steve

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

Re: CreateImageFromTwain not working

Post by Loïc » Tue Oct 20, 2009 4:22 pm

Hi Steve,

I ran your code as is -> No problem.

What is your programming language ?

To prevent your program from twain dialog just add a call to Twain1.TwainSetHideUI(True)

Kind regards,

Loïc

steve888
Posts: 7
Joined: Wed Oct 14, 2009 9:42 pm

Re: CreateImageFromTwain not working

Post by steve888 » Wed Oct 21, 2009 5:27 pm

Hi Loic,

What I discovered was that I needed to re-download the SDK. There must have been some updates in there that corrected the issue.

Thanks,
Steve

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest