Home › Forums › TWAIN Classic › Transfer of PDF from C#
- This topic has 3 replies, 3 voices, and was last updated 8 years, 7 months ago by brianmanee.
- AuthorPosts
Hello everybody.
I have a Kodak i1220+. I want to scan files and retrieve them as PDFs.
I am using this project http://www.codeproject.com/Articles/171666/Twain-for-WPF-Applications-Look-Ma-No-Handles for my application.
Right now, the first issue I see is that I get a memory buffer but no indication of its size, so I setup to add a TW_IMAGEMEMXFER structure and to import an appropiate function
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwMemory
{
public int Flags;
public int Length;
public IntPtr TheMem;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwImageMemXFer
{
public short Compression;
public int BytesPerRow;
public int Columns;
public int Rows;
public int XOffset;
public int YOffset;
public int BytesWritten;
public TwMemory Memory;
}
[DllImport("twain_32.dll", EntryPoint = "#1")]
private static extern TwRC DSmemxfer([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg,
[In, Out] TwImageMemXFer pxfr);
I added a call to my function right after the function that calls DG.Image / DAT.ImageNativeXFer / MSG.Get
rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
if (rc != TwRC.XferDone)
{
CloseSrc();
return pics;
}
rc = DSmemxfer( appid, srcds, TwDG.Image, TwDAT.ImageMemXfer, TwMSG.Get, pimagememx);
if (rc != TwRC.Success)
{
CloseSrc();
return pics;
}
All I get is a scanner driver error code 8739 (tested against a Ricoh NRG MP 161), and I have been left wondering if I somehow have made a mistake while implementing the function or it is other kind of error (v.g., not calling my function in the right moment).
Any suggestions?
Also if someone can points me to code that imports image in a format other than DIB/BMP it would be interesting.
Thanks in advance.
Ok, I have been reading a little more and this time I didn’t skip the BOOORING parts of the spec, so I found it out.
Just for the benefit of whoever finds this post, a brief answer:
Twain has transfer modes, the native mode (TwDAT.ImageNativeXfer in my code) receives only an OS-dependent format; for example for windows a DIB image. From the header the application can retrieve the size of the image –> the number of bytes; so far I have seen no method that tells the size of the buffer returned by the native transfer mode.
The TwDAT.ImageMemXfer just points that the transfer must be done using memory mode, which is a completely different transfer method. It returns a bitmap.
To get the PDF (or other custom formats) from the scanner, one should use the DiskFile transfer mode.
You means you need to scan files to PDF with C#, right?
I only know a PDF creating control with C#.
So sorry I can’t help you.
But welcome anyone to share solutions.Hope this will help you…..PDF from C#
Brian
- AuthorPosts