Home › Forums › TWAIN Classic › Need help with IMPRINTER
- This topic has 6 replies, 4 voices, and was last updated 14 years, 5 months ago by ScannerProgrammer.
- AuthorPosts
I have gotten as far as setting the capabilities for cap_printerenabled to true.
However I need to be able to print a custom string ( date, scan document count etc)
Once I set the printer_enabled where do I go from there?
this is one of the areas of the spec that I never really understood, at least from the windows environment. with the number of devices that support this capability vs the number of non-twain solutions to doing this why do this in twain? I have similar views on multi-image tiff conversions (or really almost any sort of image filetype conversions) – do them outside of twain and avoid the vendor specific issues, leave the twain interaction to getting a valid image of high enough quality in low enough time..
but then maybe I just never ‘got’ the value of these capabilities.Do you really need to do this in twain?
.
The users that I work for would like to be able to print information on the back of scanned pages as to keep a physical record of things being scanned.
I’m sure there are better and easier ways to accomplish this same goal but this is what they want so I have to give it to them.
You can set the text with the capability CAP_PRINTERSTRING. Please refer to page 9-70 of the TWAIN 2.0 specification.
Best regards,
Kaij
This is what I have so far
using TwainLib;
if (HasCapability(CAPABILITIES.PRINTER))
{
SetCap(CAPABILITIES.PRINTER, (short)PRINTER.ENDORSER_BOTTOMAFTER);
SetCap(CAPABILITIES.PRINTERENABLED, (short)BOOL.True);
}if (HasCapability(CAPABILITIES.PRINTERINDEX))
{
SetCap(CAPABILITIES.PRINTERINDEX, (short)1);
SetCap(CAPABILITIES.PRINTERMODE, (short)PRINTERMODE.SINGLESTRING);}
all of that works but as far as printer string
if(HasCapability(CAPABILITIES.PRINTERSTRING))
{
string date = DateTime.Today.ToString(“ddMMMyyyy”);Capability cp = new Capability(CAPABILITIES.PRINTERSTRING, TYPES.STR255, date);
It takes me to this area
public Capability(CAPABILITIES capName, TYPES iType, object value)
{
Cap = (short)capName;
ConType = (short)CONTAINERS.ONEVALUE;
Int32 strptr = default(Int32);
switch (iType)
{
case TYPES.FIX32:
conHandle = Marshal.AllocHGlobal(2 + Marshal.SizeOf(typeof(Fix32)));
Marshal.WriteInt16(conHandle, 0, (short)iType);
Marshal.WriteInt16(conHandle, 2, ((Fix32)value).Whole);
Marshal.WriteInt16(conHandle, 4, (short)((Fix32)value).Frac);
break;default:
conHandle = GlobalMemory.GlobalAlloc(0x42, 6);
IntPtr pv = GlobalMemory.GlobalLock(conHandle);
Marshal.WriteInt16(pv, 0, (short)TYPES.INT16);
Marshal.WriteInt32(pv, 2, Convert.ToInt32(value)); <--- errors here saying cannot convert string to intGlobalMemory.GlobalUnlock(conHandle);
break;
I am not familiar with the Marshal method you are using to allocate and fill the capability. But it looks to me that you are not allocating enough memory.
There is an example in the spec in section 2-19 for STR32 that should be easy to change to STR255.
Marshal.WriteInt32(pv, 2, Convert.ToInt32(value));
If Value is a STR255 then you probably want to use a method similar to
Marshal.WriteString(pv, 255, value);You might also want to do a MSG_GET on CAP_PRINTERSTRING and see what is supported. There might be some predefined strings in the enumeration.
Regards,
Jim Watters**************************************************
JFL Peripheral Solutions Inc.
http://www.jflinc.com/
Your Expert Source of Custom Software and Services
for TWAIN Applications, Data Sources,
Peripheral Drivers and Support Software.
**************************************************@jimwatters wrote:
I am not familiar with the Marshal method you are using to allocate and fill the capability. But it looks to me that you are not allocating enough memory.
There is an example in the spec in section 2-19 for STR32 that should be easy to change to STR255.
Marshal.WriteInt32(pv, 2, Convert.ToInt32(value));
If Value is a STR255 then you probably want to use a method similar to
Marshal.WriteString(pv, 255, value);You might also want to do a MSG_GET on CAP_PRINTERSTRING and see what is supported. There might be some predefined strings in the enumeration.
Regards,
Jim Watters**************************************************
JFL Peripheral Solutions Inc.
http://www.jflinc.com/
Your Expert Source of Custom Software and Services
for TWAIN Applications, Data Sources,
Peripheral Drivers and Support Software.
**************************************************The marshal method just writes the handle into memory. My issue is I just need to see how someone (who has set an imprinter through code) did theirs.
Parts of this twain spec are greek to me. Some others are easy to understand. This is the greek part.
- AuthorPosts