【发布时间】: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