0

如何从扫描仪获取图像输出作为 HTML 文件输入字段的文件输入。我正在使用 dynasoft web twain api 来扫描图像。http://www.dynamsoft.com/Support/DWTGuide/Dynamic%20Web%20TWAIN%20SDK.html#Manual

获取扫描图像的片段 -

    var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
    DWObject.IfDisableSourceAfterAcquire = true;    // Source will be closed automatically after acquisition.
    DWObject.SelectSource();                        // Select a Data Source (a device like scanner) from the Data Source Manager.
    DWObject.OpenSource();                          // Open the source. You can set resolution, pixel type, etc. after this method. Please refer to the sample 'Scan' -> 'Custom Scan' for more info.
    DWObject.AcquireImage();

文件输入的片段 -

<input type="file" id="fileselect" accept="image/*,application/pdf" capture="camera" app-file-select="onFileSelect($files)" app-change="getFile($files)" app-model="file" style="display:none">

Html 文件在服务器端作为 MultipartFile 处理。

提前致谢

4

2 回答 2

1

您不需要创建输入元素。只需使用 API HTTPUploadAllThroughPostAsPDFHTTPUploadThroughPostAsMultiPagePDF。在服务器端,您可以使用任何您喜欢的编程语言。

例如,ASP.NET:

<%@ Page Language="C#" %>

<%
    try
    {
        String strImageName;
        HttpFileCollection files = HttpContext.Current.Request.Files;
        HttpPostedFile uploadfile = files["RemoteFile"];
        strImageName = uploadfile.FileName;

        uploadfile.SaveAs(Server.MapPath(".") + "\\UploadedImages\\" + strImageName);

    }
    catch
    {
    }
%>

使用RemoteFile提取文件内容。

于 2015-07-02T06:08:43.247 回答
0

Dynamic Web Twain (DWT) 不会将捕获的图像提供给浏览器,因此浏览器可以将其用作输入字段。但我们必须将其上传到我们的服务器。DWT 为此提供了许多功能。您可以使用以下任何满足您需求的东西 -

FTP功能:

  • FTP上传()
  • FTPUploadAllAsMultiPageTIFF()
  • FTPUploadAllAsPDF()
  • FTPUploadAsMultiPagePDF()
  • FTPUploadAllAsMultiPageTIFF()
  • FTPUploadAllAsPDF()
  • FTPUploadAsMultiPagePDF()
  • FTPUploadAsMultiPageTIFF()
  • FTPUploadDirectly()
  • FTPUploadEx()

HTTP 功能:

  • HTTPUploadAllThroughPostAsMultiPageTIFF()
  • HTTPUploadAllThroughPostAsPDF()
  • HTTPUploadThroughPost()
  • HTTPUploadThroughPostAsMultiPagePDF()
  • HTTPUploadThroughPostAsMultiPageTIFF()
  • HTTPUploadThroughPostDirectly()
  • HTTPUploadThroughPostEx()

你更清楚哪一个适合你。例如,如果您想将所有图像上传为 PDF,并且喜欢使用 HTTP 发布请求,则应使用“HTTPUploadAllThroughPostAsPDF”。

DWObject.HTTPUploadAllThroughPostAsPDF(location.hostname, $POST_URL, 'my-test-file.pdf');

您可能需要与文件一起传递一些其他字段。在这种情况下,您可以使用“SetHTTPFormField”。这是将图像上传为 PDF 的详细示例。

DWObject.SetHTTPFormField("field1", "field1 value");
DWObject.SetHTTPFormField("field2", "field2 value");
DWObject.IfSSL = ('https:' === location.protocol);
if (location.port != '') {
    DWObject.HTTPPort = location.port;
} else {
    DWObject.HTTPPort = (DWObject.IfSSL) ? 443 : 80;
}
DWObject.HTTPUploadAllThroughPostAsPDF(location.hostname, $POST_URL, 'my-test-file.pdf');
于 2015-12-31T04:13:50.227 回答