Page 1 of 1

Multipage PDFs from web twain

Posted: Wed Dec 29, 2010 8:24 pm
by newage
Hi,
Is it possible to save multipage PDFs from web twain using javascript+vb.net?
Thanks.

Re: Multipage PDFs from web twain

Posted: Thu Dec 30, 2010 8:49 am
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

Re: Multipage PDFs from web twain

Posted: Thu Jan 06, 2011 8:34 pm
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);
}
}
}

Re: Multipage PDFs from web twain

Posted: Wed Jan 12, 2011 9:57 am
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

Re: Multipage PDFs from web twain

Posted: Tue Mar 08, 2011 8:05 pm
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?

Re: Multipage PDFs from web twain

Posted: Thu Mar 17, 2011 6:14 pm
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