【问题标题】:Calling Functions in QZ-Print Java Applet doesn't work in PHP在 QZ-Print Java Applet 中调用函数在 PHP 中不起作用
【发布时间】:2015-10-01 22:09:59
【问题描述】:

我正在尝试使用 Java 插件从浏览器打印到票证打印机的原始打印。我已经用 HTML 和 Javascript 编写了一个运行正常的测试程序,但现在我正在尝试将代码传输到 php 脚本,以便在更大的应用程序中打印票证。每当我从应用程序调用函数时,我都会在 Firefox 调试中遇到这种错误。 “TypeError:qz.findPrinter 不是函数”。

我将原始测试程序的扩展名从 .html 更改为 .php,现在我也收到了错误。

java 中的任何函数都以“qz”开头。

这是供参考的插件 https://code.google.com/p/jzebra/wiki/TutorialWebApplet

我认为这是我对 php 不了解的东西,因为它可以作为 .html 文件工作,但无论如何我已经包含了整个脚本。 php 是从 xampp 运行的。

感谢您的宝贵时间。

<html>

<head><title>Receipt Test</title>
<script type="text/javascript" src="js/deployJava.js"></script>
<script type="text/javascript">
deployQZ();

function deployQZ() {
    var attributes = {id: "qz", code:'qz.PrintApplet.class', 
        archive:'qz-print.jar', width:1, height:1};
    var parameters = {jnlp_href: 'qz-print_jnlp.jnlp', 
        cache_option:'plugin', disable_logging:'false', 
        initial_focus:'false'};
    if (deployJava.versionCheck("1.7+") == true) {}
    else if (deployJava.versionCheck("1.6+") == true) {
        attributes['archive'] = 'jre6/qz-print.jar';
        parameters['jnlp_href'] = 'jre6/qz-print_jnlp.jnlp';
    }
    deployJava.runApplet(attributes, parameters, '1.5');
}

function countSpace(product, price, section)    {
var spaceNeeded = (section - product.length - price.toString().length);
var spaces = "";
for(i=0; i < spaceNeeded; i++) {
spaces += " ";
    }
return (product + spaces + price);  
}

function findPrinter() {
     // Searches for locally installed printer with "zebra" in the name
     qz.findPrinter("zebra");


     // Hint:  Carriage Return = \r, New Line = \n, Escape Double Quotes= \"


    var ticketTime = new Date();    
    var singleLine = "\n------------------------------------------\n";
    var doubleLine = "\n==========================================\n";
    var product = ["Mirdan Tuzlama", "Suckuklu Pide" ];
    var price = [8.00, 8.00];
    var prodCharLength = 37;
    var finCharLength = 42;
    var subTotal = {name:"Subtotal", value:0};

    for(i=0;i<product.length;i++) {
    subTotal.value += price[i];
    } 

    var tax = {name:"Tax", value:((20/100)*subTotal.value)};
    var total = {name:"Total", value:(subTotal.value-tax.value)}; 
    var ticketEnd = "                Thank You\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    var productSec = "";
    tax.value = 0 - tax.value;
    for(j=0;j<product.length;j++) {
    var priceloop = price[i];
    productSec += (" - 1 " + countSpace(product[j], price[j],prodCharLength));
        if (j<=(product.length-2)){
        productSec += "\n"
        }
    }


    qz.append("\nDate:" + ticketTime.getDate() + "/" 
                        + (ticketTime.getMonth()+1) + "/" 
                        + ticketTime.getFullYear() 
            + "\nTime:" + ticketTime.getHours() + ":" 
                        + ticketTime.getMinutes() 
            + "\nTable: B10\nTicket No:2"               
            //+ singleLine + " - 1 " + product1 +"                   8.00\n - 1 " + product1 +"                    8:00" 
            + singleLine + productSec
            + doubleLine + countSpace(subTotal.name, subTotal.value,finCharLength) 
            + '\n' + countSpace(tax.name, tax.value,finCharLength)
            + '\n' + countSpace(total.name, total.value,finCharLength)              
            + doubleLine + ticketEnd);

    qz.print(); 

}
</script>

<body>

<input type="button" onClick="findPrinter()" value="Print ESCP" /><br />
</body>

【问题讨论】:

  • 这个例子中没有任何 PHP。你能澄清一下问题吗? QZ Print 使用 JavaScript API,JavaScript 在客户端运行,而 PHP 在服务器上运行。将两者混合需要更好地理解这些超出软件 API 或使用范围的技术。我们在这里有两个 php 示例:github.com/qzind/qz-print/wiki/raw-printing#using-echo

标签: javascript java php printing applet


【解决方案1】:

"TypeError: qz.findPrinter 不是函数"

  • 在 QZ "Tray" 1.9(桌面应用程序)中,qz.findPrinter(...) 被定义为 preemptive 函数,created by qz-websocket.js 并且必须包含在您的项目中才能公开。
    如果您未包含 qz-websocket.js,则会出现此消息。

  • 在 QZ "Print" 1.9 (Java Applet) 和更早版本中,qz.findPRinter(...) 是通过使用 Java LiveConnect 调用的 Java Applet 公开的,因此这是 Applet 未加载的标志。
    如果您的小程序未正确加载,则会出现此消息。

注意: 1.9 既可以用作桌面应用程序,也可以用作 Java 小程序。

弃用警告: 1.9 及更早版本为EOL。 QZ Tray 2.0 及更高版本,API 发生了显着变化。迁移指南是available

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 2013-05-31
    • 2023-04-02
    • 1970-01-01
    • 2011-07-04
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多