[英]How do i get the scanned image from Scanner as an input for HTML File input field using web twain?
如何從掃描儀獲取圖像輸出作為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處理。
提前致謝
您無需創建輸入元素。 只需使用API HTTPUploadAllThroughPostAsPDF或HTTPUploadThroughPostAsMultiPagePDF即可 。 在服務器端,您可以使用任何喜歡的編程語言。
例如,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提取文件內容。
動態Web吐溫(DWT)不會將捕獲的圖像提供給瀏覽器,因此瀏覽器可以將其用作輸入字段。 但是我們必須將其上傳到我們的服務器。 DWT為此提供了許多功能。 您可以使用滿足您需求的以下任何一種產品-
FTP功能:
HTTP功能:
您更了解哪一種適合您。 例如,如果您希望將所有圖像上傳為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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.