TwainPRO FAQ

Contact Support



Q1How can I determine if I have the latest version of a Pegasus control?
Q2How do I set and check capabilities with TwainPRO?
Q3How do I set and check advanced capabilities with TwainPRO?
Q4How do I scan from an Automatic Document Feeder using TwainPRO?
Q5How can I change the Layout Size and DPI for scanned images?
Q6Sometimes it appears that Setting a capability has no effect the image scanned by my scanner. Why is this?
Q7How do I save scanned TIFF images to a multi-page TIFF file?
Q8I am using Visual FoxPro and the Post_Scan event is not firing. Why?
Q9How do I distribute my application (in .NET, Delphi, VB etc.)?
Q10Where can I obtain the TWAIN specification?
Q11How do I close the scanner dialog after scanning has completed?
Q12How do I determine if the hardware is on and ready?
Q13Where can I obtain a test application that uses TwainPRO?
Q14What DLL's do I need to distribute with my application?
Q15What value is used to set the ICAP_AUTODISCARDBLANKPAGES advanced capability?

Q1: How can I determine if I have the latest version of a Pegasus control?
Please download the PegConnect utility program from the following link: PegConnect
or reference the Latest Builds page.

Q2: How do I set and check capabilities with TwainPRO?
TwainPRO uses a single property for basic capability selection and a set of properties that act on the selected capability. Regardless of which capability is selected, the same properties are always used to read and set the capability. The Capability property is the selection property and it is an enumerated property that contains a list of the 31 capabilities supported by TwainPRO.

Reading a capability:
Once the capability has been selected with the Capability property, it should be checked to see if the Data Source supports it. This is done with the CapSupported property. This is a boolean property that returns True if the capability is supported or False if it is not.

If the capability is supported, the CapType property should be checked to see what type of container the Data Source uses to pass values back to TwainPRO. TWAIN defines four types of containers to negotiate values between the application (TwainPRO) and the Source. They are:

TWCAP_ONEVALUE
TWCAP_ENUM
TWCAP_RANGE
TWCAP_ARRAY

The container determines which TwainPRO properties should be used to check the values for the current capability.

The type of container returned depends on the capability. See the TwainPRO help for an individual capability to determine which type of containers to expect.

The following sample code illustrates how to check the container type for the TWCAP_PIXELTYPE capability.

TwainPRO1.Capability = TWCAP_PIXELTYPE
If TwainPRO1.CapSupported then
MsgBox "Cap Type: " & TwainPRO1.CapType
End If


Setting a capability:
Like reading a capability, the Capability property is used to determine which capability will be negotiated. Another set of properties is used to set a capability, and they all end with the word "out". Each property used to read a capability has a corresponding property for setting the capability. For example, the CapTypeOut property determines which type of container will be used to set the cap. Once the properties are set, the SetCapOut method negotiates the new values.

The following sample code illustrates how to set the value of the PixelType capability:

TwainPRO1.Capability = TWCAP_PIXELTYPE
If (TwainPRO1.CapSupported) then
TwainPRO1.CapTypeOut = TWCAP_ONEVALUE
TwainPRO1.CapValueOut = 0
TwainPRO1.SetCapOut
End If

Q3: How do I set and check advanced capabilities with TwainPRO?
In TwainPRO v3.0, use the CapAdvanced property for accessing all of the advanced capabilities that are supported in the Twain specification. The CapAdvanced property is used by setting the Capability property to the TWCAP_USECAPADVANCED enumerated value and then using any of the allowable capability values from the Twain specification.

The following sample code illustrates how to set an advanced capability:

TwainPRO1.Capability = TWCAP_USECAPADVANCED
TwainPRO1.CapAdvanced = ICAP_BARCODEDETECTIONENABLED
If (TwainPRO1.CapSupported) Then
TwainPRO1.CapTypeOut = TWCAP_ONEVALUE
TwainPRO1.CapValueOut = 1
TwainPRO1.SetCapOut
End If

Q4: How do I scan from an Automatic Document Feeder using TwainPRO?
If your scanner supports the use of an Automatic Document Feeder, there are several capabilities that can be used with this feature.

To enable scanning from a document feeder, use the TWCAP_FEEDERENABLED to do this. Below is an example:

TwainPRO1.Capability = TWCAP_FEEDERENABLED
If (TwainPRO1.CapSupported) Then
TwainPRO1.CapTypeOut = TWCAP_ONEVALUE
TwainPRO1.CapValueOut = 1 ' Sets document acquisition source to feeder if available
TwainPRO1.SetCapOut
End If

Q5: How can I change the Layout Size and DPI for scanned images?
Changing the Layout Size for scanned images is accomplished by using the TwainPRO method, SetImageLayout. This method sets the Left, Top, Right, and Bottom sides of the Image Layout rectangle for the current Data Source.

The Image Layout rectangle defines what portion of the Data Source's scanning area is acquired. Call this method after OpenSession and before StartSession.

It is also a good idea to set the TWCAP_UNITS capability for the scanner prior to using the SetImageLayout method to specify the unit of measure you'll be using.

The following sample code illustrates how to set the Image Layout rectangle to 6.5 inches X 9 inches:

TwainPRO1.Capability = TWCAP_UNITS
If TwainPRO1.CapSupported = True Then
TwainPRO1.CapTypeOut = TWCAP_ONEVALUE
TwainPRO1.CapValueOut = 0 ' set units to Inches
TwainPRO1.SetCapOut
End If

TwainPRO1.SetImageLayout 1, 1, 7.5, 10


To change the DPI for scanned images:
This is accomplished by using the TWAIN capabilities, TWCAP_XRESOLUTION,
TWCAP_YRESOLUTION. Also, it is important to set the TWCAP_UNITS capability equal to
TWUN_INCHES prior to setting the resolution capabilities.

The following sample code illustrates how to set the DPI of scanned images to 300 DPI:

TwainPRO1.Capability = TWCAP_UNITS
If TwainPRO1.CapSupported Then
TwainPRO1.CapTypeOut = 0'
TwainPRO1.CapValueOut = 0' set units to Inches
TwainPRO1.SetCapOut
End If

TwainPRO1.Capability = TWCAP_XRESOLUTION
If TwainPRO1.CapSupported Then
TwainPRO1.CapTypeOut = 0
TwainPRO1.CapValueOut = 300
TwainPRO1.SetCapOut
End If

TwainPRO1.Capability = TWCAP_YRESOLUTION
If TwainPRO1.CapSupported Then
TwainPRO1.CapTypeOut = 0
TwainPRO1.CapValueOut = 300
TwainPRO1.SetCapOut
End If

Q6: Sometimes it appears that Setting a capability has no effect the image scanned by my scanner. Why is this?
There are a couple of reasons this issue may be occurring:

Resolution 1: Please make sure that you call OpenSession before setting the capabilities. For example:

TwainPRO1.SelectSource
TwainPRO1.ShowUI = False
TwainPRO1.OpenSession

Resolution 2: Not all TWAIN devices support all TWAIN capabilities. Because of this, you must check to see if a TWAIN capability is supported by your device before setting it.

To do this, TwainPRO provides a property called CapSupported, which will return True if the capability is supported and False if not.

Below is an example of how to check this property:

TwainPRO1.Capability = TWCAP_PIXELTYPE
If (TwainPRO1.CapSupported) Then
' If setting capability is supported this code will be executed
End If

Q7: How do I save scanned TIFF images to a multi-page TIFF file?
To save images to a multi-page TIFF file, you'll need to set the SaveMultiPage property to True. Then in the TwainPRO1_PostScan Event, use the SaveFile method to set the filename to a valid file and save the file.

The following sample code illustrates how to save to a multi-page file:

Private Sub tp_PostScan(Cancel As Boolean)
' When scanning from a document feeder, the PostScan event will fire
' after each page is scanned.
TwainPRO1.SaveTIFCompression = TWTIF_CCITTFAX4
TwainPRO1.SaveMultiPage = True
TwainPRO1.SaveFile App.Path & "\multiPage.tif"
End Sub

Q8: I am using Visual FoxPro and the Post_Scan event is not firing. Why?
The Application.AutoYield = .F. command needs to be set in Visual FoxPro where the program begins.

Q9: How do I distribute my application (in .NET, Delphi, VB etc.)?
PLEASE NOTE: You must have your unlock codes to distribute your application in the majority of the scenarios outlined below. If you do not have these please complete the form at http://www.pegasusimaging.com/lostcodes.htm and the codes will be sent to you.

1) If you are using .NET as your development tool you must call the UnlockPICTwainPRO.PS_Unlock function and pass as the parameters the same 4 unlock codes that were received at the time of purchase.

For C# Developers: Call the static PS_Unlock function in the class constructor BEFORE the generated call to InitializeComponent () as follows:

Public FormMain()
{
UnlockPICTwainPRO.PS_Unlock(1234, 1234, 1234, 1234);
InitializeComponent();
}

For Visual Basic. NET Developers:
Call the static PS_Unlock function in the class constructor (i.e. New function) BEFORE the generated call to InitializeComponent () as follows:

Public Sub New ()
MyBase.New ()

UnlockPICTwainPRO.PS_Unlock(1234, 1234, 1234, 1234)

IntializeComponent ()

End Sub

2) If you are using Delphi as your development tool you must declare the PS_Unlock function as outlined below:

procedure PS_Unlock(pw1, pw2, pw3, pw4: LongInt); stdcall external 'TwnPRO4.dll ';

begin

Application.Initialize;
PS_Unlock(123456789,123456789,987654321,12345);
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

3) If you are using the TwainPRO COM object in VC++ as your development tool you must declare the PS_Unlock function as outlined below:

The TwainPRO COM Object contains a locking mechanism that does not permit you to distribute applications created with evaluation versions of TwainPRO. When you register TwainPRO, you are given a set of 4 numeric registration codes that are your individual password set for unlocking TwainPRO for distribution.

If you do not unlock TwainPRO, applications will not run on end user machines.

Before distributing an application, you must unlock TwainPRO.

TP_Open.cpp is included with TwainPRO to handle licensing for the COM Object. You can find TP_Open.cpp in the TwainPRO VCCOM\Include directory. In the TP_Open.cpp function, locate the call to PS_Unlock(). Replace the four parameters in that call with the four registration codes you obtained when you purchased TwainPRO. When you compile your project, TwainPRO should be unlocked meaning that you should no longer see the "Evaluation" message boxes.

4) If you are using the TwainPRO control as a COM object in VB you must declare the PS_Unlock function as outlined below:

   1) Add a reference to the TwainPRO control via Project|References.

   2) Declare the PS_Unlock function as follows:

   Private Declare Sub ControlUnlock Lib "twainpro4" Alias "PS_Unlock" (ByVal pw1 As Long, ByVal pw2 As Long, ByVal    pw3 As Long, ByVal pw4 As Long)

   3) Dim the TwainPRO control object:

   Dim WithEvents tp As TWNPRO4Lib.TwainPRO

   4) Call the unlock method:

   ControlUnlock 1234, 1234, 1234, 1234
   Set tp = New TWNPRO4Lib.TwainPRO
   tp.hParentWnd = Form1.hWnd

5) If you are using the control within HTML you must obtain a web license string. This web license string is received from our sales department when the web license is purchased. The web license string is passed as the parameter to the IntegratorWeb method. Please refer to http://www.pegasusimaging.com/weblicfaq.htm for more information on using the control within a web environment.

6) If you are using the TwainPRO ActiveX Control open your project with your development tool (Visual Basic or Delphi) and rebuild the EXE. The new registration information will be automatically incorporated in the new executable.

Q10: Where can I obtain the TWAIN specification?
You can download this from the TWAIN.org site at: http://twain.org/docs/Spec1_9_197.pdf .

Q11: How do I close the scanner dialog after scanning has completed?
You need to do one of the following:
1) Call the CloseSession method in the PostScan event.
2) Set the Cancel parameter = True in the PostScan event.

Q12: How do I determine if the hardware is on and ready?
The TWCAP_DEVICEONLINE capability can be used to determine the status of the hardware.

Q13: Where can I obtain a test application that uses TwainPRO?
There is an application called TwainPRODemo.exe that is installed with the TwainPRO install. It is located in: C:\Program Files\Pegasus Imaging\TwainPRO\V4.0\Samples\ActiveX-COM\VB6\TwainPRODemo. This application can be used to determine if certain TWAIN capabilities are supported.

Q14: What DLL's do I need to distribute with my application?
For .NET Windows Forms Applications:
PEGASUSIMAGING.WINFORMS.TWAINPRO4.DLL

For All Other Applications:
TWNPRO4.DLL
TWNLIB4.DLL

You must also distribute STDOLE2.TLB and OLEAUT32.DLL that are Microsoft support files. These must be registered prior to registering TWAINPRO4.DLL and TWNLIB4.DLL.

If you are using the TwainPRO COM component, it needs to be registered after it is installed. Make sure that your installation program registers the TWAINPRO4.DLL before you run your application.

Q15: What value is used to set the ICAP_AUTODISCARDBLANKPAGES advanced capability?
The value for the ICAP_AUTODISCARDBLANKPAGES advanced capability is 4404 or in hexidecimal, 1134.


Sitemap | © 2008 Pegasus Imaging Corporation. All Rights Reserved. | Privacy Statement.