2

我们有一个 kiosk 应用程序,我们曾经在其中使用 windows print 打印收据。现在我们有一个类 clsid:CCB90152-B81E-11D2-AB74-0040054C3719 和其中的一些功能,我需要使用这些功能直接使用此对象进行打印,而不是使用 Windows 打印。我们甚至有一些与此相关的代码,我尝试使用其中一些代码来打印示例消息。我没有成功。

function printtext(){
        try{


        doPrinterInit();
        alert("after init print");
        doPrint(document.getElementById('fname').value, true, true);
        doPrintFeed();
        doCut();

        alert("printed");
        //document.getElementById('display').innerHTML = document.getElementById('fname').value;
        }
        catch(e){
            //alert('Error: ' + e.description);
        }

    }

</SCRIPT>
</HEAD>
<BODY onLoad="Initialize()">
<OBJECT ID="posPrinter" CLASSID="clsid:CCB90152-B81E-11D2-AB74-0040054C3719"></OBJECT>
    Utility File


        First name: <input type="text" name="fname" id="fname"><br>

        <button onclick="printtext()">Print</button>

    <div id="display"></div>
</BODY>
</HTML>

doprinterinit()调用的函数如下。

function doPrinterInit() {
    try {
        if (posPrinter.Open(PRINTER_ID) == 0) {
            alert("opened");
            if (posPrinter.Claim(CLAIM_TIMEOUT) == 0) {
            alert("claim timeout successful");
                posPrinter.DeviceEnabled = true;
                if (posPrinter.DeviceEnabled) {
                alert("fine device enabled");
                    // all is fine
                } else {
                alert("device not enabled");
                    throwException(105, 'doPrinterInit(): Could not Enable Printer', EVENT_TYPE_ERROR);
                }
            } else {
                throwException(posPrinter.ResultCode, 'doPrinterInit(): Could not Claim Printer in ' + CLAIM_TIMEOUT + ' ms', EVENT_TYPE_ERROR)
            }
        } else {
        alert("");
            throwException(posPrinter.ResultCode, 'doPrinterInit(): Could not Open Printer', EVENT_TYPE_ERROR);
        }
    } catch(e) {
        throw e;
    }
}

我去设备未启用警报..请有人帮助我。我不知道该如何处理。

4

0 回答 0