Click here to Skip to main content
14,828,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to scan a document from my web application using javascript.
How can I do this.
Posted

How do you mean? It is normally not possible for a web application to retrieve an image directly from a scanner. The user should use it's own scanner software to store it as an image file. The image file can then be uploaded.

Good luck!
   
I found one solution for scanning Documents but not using Javascript.
Here is the code for it.

WiaClass wiaManager = null;		// WIA manager COM object
CollectionClass wiaDevs = null;		// WIA devices collection COM object
ItemClass wiaRoot = null;		// WIA root device COM object
CollectionClass wiaPics = null;		// WIA collection COM object
ItemClass wiaItem = null;		// WIA image COM object
try
    {
      string fileName = "myFile";
      wiaManager = new WiaClass();	// create COM instance of WIA manager

  wiaDevs = wiaManager.Devices as CollectionClass;// call Wia.Devices to get all devices

   if ((wiaDevs == null) || (wiaDevs.Count == 0))
   {
        Response.Write("<script>alert('No Scanner found');</script>");
        return;
   }
   else
   {
       object selectUsingUI = System.Reflection.Missing.Value;			
       wiaRoot = (ItemClass)wiaManager.Create(ref selectUsingUI);//letUser select device
       
     if(wiaRoot == Null	)
        return;

    // this call shows the common WIA dialog to let the user select a picture:
     wiaPics = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor) as     CollectionClass;
              
      if (wiaPics == null)
            return;
      bool takeFirst = true;	         // this sample uses only one single picture
      string ImgName = Server.MapPath("~\\thumbnails").ToString() + "\\" + fileName;
    
     foreach (object wiaObj in wiaPics)	// enumerate all the pictures the user selected
      {
          if (takeFirst)
          {
          wiaItem = (ItemClass)Marshal.CreateWrapperOfType(wiaObj, typeof(ItemClass));
          // transfer picture to our temporary file
          wiaItem.Transfer(ImgName + ".jpg", false); 
          makeThumbnail(fileName + ".jpg");        
     takeFirst = false;								
    }
    Marshal.ReleaseComObject(wiaObj);		
   }
}
}
catch (Exception ee)
{
}
finally
(
if (wiaItem != null)
    Marshal.ReleaseComObject(wiaItem);		// release WIA image COM object
if (wiaPics != null)
    Marshal.ReleaseComObject(wiaPics);		// release WIA collection COM object
if (wiaRoot != null)
    Marshal.ReleaseComObject(wiaRoot);		// release WIA root device COM object
if (wiaDevs != null)
    Marshal.ReleaseComObject(wiaDevs);	// release WIA devices collection COM object
if (wiaManager != null)<pre>

Marshal.ReleaseComObject(wiaManager); // release WIA manager COM object
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900