本文介绍了扫描文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用javascript从我的Web应用程序中扫描文档.
我该怎么做.

I want to scan a document from my web application using javascript.
How can I do this.

推荐答案


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>


元帅.ReleaseComObject(wiaManager); //释放WIA管理器COM对象
}


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


这篇关于扫描文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 08:45