Multipage PDFs from web twain

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
newage
Posts: 2
Joined: Wed Dec 29, 2010 8:19 pm

Multipage PDFs from web twain

Post by newage »

Hi,
Is it possible to save multipage PDFs from web twain using javascript+vb.net?
Thanks.
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Multipage PDFs from web twain

Post by Alex »

Hello,

Yes, this is possible.

First, you need to save all acquired images as PDF document in the stream - please read description of the AcquiredImage.GetAsStream method in the documentation or see this FAQ: http://www.vintasoft.com/vstwain-dotnet ... magesAsPdf

Next, you need to upload stream to the server - please read description of the HttpUpload.AddFileField method in the documentation.

Best regards, Alexander
newage
Posts: 2
Joined: Wed Dec 29, 2010 8:19 pm

Re: Multipage PDFs from web twain

Post by newage »

Hi, thanks for your answer.
I tried both examples from FAQs and from help documentation for GetAsStream Method.
If I’m following FAQ example, I’m getting error “AquiredImgae.0 is null or not an object” and device.AcquiredImages.Count is always 1 even if I’ve scanned 10 pages.

Help documentation example gives me error “ImageFileFormat is undefined”
Thanks.

if (acquireModalState == 2) {
if (firstImage) {
// get the first image as PDF stored in the memory
mem = device.AcquiredImage[0].GetAsStream(ImageFileFormat.PDF);
firstImage = false;
}
else {
// add image to PDF stored in the memory
for (var x=1; x=device.AcquiredImages.Count-1; x++) {
device.AcquiredImages[x].SaveToStream(mem, ImageFileFormat.PDF);
}
}
}
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Multipage PDFs from web twain

Post by Alex »

Hello,
Help documentation example gives me error “ImageFileFormat is undefined”
Your code has 3 mistakes:
  • Wrong name of property in the line "mem = device.AcquiredImage[0].GetAsStream(ImageFileFormat.PDF);". You need to use "AcquiredImages" instead of "AcquiredImage".
  • JavaScript cannot access Indexer of class, i.e. line "device.AcquiredImages[0]" is not correct in JavaScript
  • JavaScript does not know anything about the ImageFileFormat enumeration. Here are constants of ImageFileFormat enumeration: BMP - 0, JPEG - 1, TIFF - 2, PNG - 3, GIF - 4, PDF - 5.
And here is the correct code:

Code: Select all

if (acquireModalState == 2)
{
  if (firstImage)
  {
     // get the first acquired image as PDF stored in the memory
     mem = device.AcquiredImage[0].GetAsStream(5);
     firstImage = false;
   }
  else
  {
    // add each (not first) acquired image to PDF stored in the memory
    device.AcquiredImages.Last.SaveToStream(mem, 5);
  }
}
Best regards, Alexander
jimiscott
Posts: 1
Joined: Tue Mar 08, 2011 7:59 pm

Re: Multipage PDFs from web twain

Post by jimiscott »

Alex, we have tried implementing the suggested code, but it seems not to work.

Our scanner is a single page scanner, but we would like to scan multiple images into a single document.

With the suggested code, after the first scan, the device.AcquireModal() method returns 3, after which the image is uploaded. Is there anyway to achieve the above?
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Multipage PDFs from web twain

Post by Alex »

Hello,

Value 3 means that scan is completed i.e. you acquired image from flatbed scanner.

You should save acquired image to the stream, start the second/third/... scan, add acquired images to the stream, upload data of the stream to the server when this is necessary.

Best regards, Alexander
Post Reply