0

我收到来自动态 Web twain 的“convertToBlob”方法的索引超出范围错误,我使用它通过扫描仪扫描文档,有人可以帮忙吗?

  dwObject.ConvertToBlob([0], EnumDWT_ImageType.IT_JPG, (result) => {
        const data = new File([result], 'Scan.jpeg', result);
        let attachmentsBlob = [];
        let attachmentObject = [];
        directAccess ? attachmentObject.push({ attachmentName: "Scan.jpeg", attachmentType: parentType, documentType: type }) : attachmentObject.push({ attachmentName: "Scan.jpeg", attachmentType: type });
        attachmentsBlob.push(data);
        this.customerAttachment(attachmentObject, attachmentsBlob).subscribe((res: any) => {
          if (res['code'] === '0000') {
            this.toastr.success("Attachement uploaded Successfully");
            if (directAccess) {
              form.patchValue(res.data[0]);
            } else {
              let scan = form.controls.customerAttachments.value;
              scan.push(res.data[0]);
              form.controls.customerAttachments.setValue(scan);
            }

          } else if (res['code'] === '0101') {
            this.toastr.error('Error', res['data']['message']);
          }
        });
      }, (errorCode, errorString) => {
        this.toastr.error(errorString);
      });
4

1 回答 1

0

不确定您是如何编写代码的。只要您扫描了内存中的文档,就不会出现此问题。

这是 Dynamic Web TWAIN v17.1的一个简单示例(命名空间与您的不同),演示如何使用ConvertToBlob

<!DOCTYPE html>
<html>

<head>
    <title>Use Dynamic Web TWAIN to Scan</title>
    <script type="text/javascript" src="Resources/dynamsoft.webtwain.initiate.js"></script>
    <script type="text/javascript" src="Resources/dynamsoft.webtwain.config.js"></script>
</head>

<body>
    <select size="1" id="source" style="position: relative; width: 220px;"></select>
    <input type="button" value="Scan" onclick="AcquireImage();" />

    <div id="dwtcontrolContainer"></div>

    <script type="text/javascript">
        Dynamsoft.DWT.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);

        var DWObject;

        function Dynamsoft_OnReady() {
            DWObject = Dynamsoft.DWT.GetWebTwain('dwtcontrolContainer');
            if (DWObject) {
                var count = DWObject.SourceCount;
                for (var i = 0; i < count; i++)
                    document.getElementById("source").options.add(new Option(DWObject.GetSourceNameItems(i), i));
            }
        }
        function AcquireImage() {
            if (DWObject) {
                var OnAcquireImageSuccess = function () {
                    DWObject.ConvertToBlob([0], Dynamsoft.DWT.EnumDWT_ImageType.IT_JPG, (result) => {
                        const data = new File([result], 'Scan.jpeg', result);
                        console.log(data);
                    }, (errorCode, errorString) => {
                        this.toastr.error(errorString);
                    });
                    DWObject.CloseSource();
                };

                DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex); 
                DWObject.OpenSource();
                DWObject.IfDisableSourceAfterAcquire = true;
                DWObject.AcquireImage(OnAcquireImageSuccess, () =>{});
            }
        }
    </script>
</body>

</html>

于 2021-09-14T05:30:13.463 回答