Dav*_*vid 6 php printing string epson
所以我从我们的网络服务器(也在办公室)打印到办公室的网络热敏打印机,这样客户就可以在网站上下订单,然后在销售部门桌面上弹出.这是我使用的代码,它工作得很好.然而,当涉及到打印单上的项目时,我希望项目文本对齐中心和价格文本对齐,但它不会让我这样做(因为它与我想的相同)所以我怎么能说新行(\n)然后反过来.我试过\ 033F和\ F已经但没有运气.任何建议?
$texttoprint = "";
//center,bold,underline - close underline, close bold
$texttoprint .= "\x1b\x61\x01\x1b\x45\x01\x1b\x2d\x02\x1b\x21\x10\x1b\x21\x20 Company name \x1b\x2d\x00\x1b\x45\x00";
$texttoprint .= "\n";
//normal text
$texttoprint .= "\x1b\x21\x00 Address";
$texttoprint .= "\n";
//normal text
$texttoprint .= "\x1b\x21\x00 Adress2";
$texttoprint .= "\n";
//normal text
$texttoprint .= "\x1b\x21\x00 Tel : ...";
$texttoprint .= "\n";
$texttoprint .= "\n";
//normal text
$texttoprint .= "\x1b\x21\x00 Website order";
$texttoprint .= "\n";
$texttoprint .= "\n";
//center,bold,underline - close underline, close bold
$texttoprint .= "\x1b\x61\x01\x1b\x45\x01\x1b\x2d\x02\x1b\x21\x10\x1b\x21\x20 Tax Invoice \x1b\x2d\x00\x1b\x45\x00";
$texttoprint .= "\n";
$texttoprint .= "\n";
//align center, normal text
$texttoprint .= "\x1b\x61\x01\x1b\x21\x00 1x product";
//align right, normal text
$texttoprint .= "\x1b\x61\x02\x1b\x21\x00 $200";
...
Run Code Online (Sandbox Code Playgroud)
正如你在这里看到的那样,最后两个是在同一条线上,我试图证明产品中心和价格合理.他们都最终居中,如果我把a/n放在中间,那么他们就会在错误的线路上正确地证明这一点.
$texttoprint = stripslashes($texttoprint);
$fp = fsockopen("192.168.0.168", 9100, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, "\033\100");
$out = $texttoprint . "\r\n";
fwrite($fp, $out);
fwrite($fp, "\012\012\012\012\012\012\012\012\012\033\151\010\004\001");
fclose($fp);
}
Run Code Online (Sandbox Code Playgroud)
您可以让打印机完成所有工作,但我认为最好将一些有关打印机特性的知识应用于输出例程。您应该知道每行可以打印多少个字符。
然后,您可以使用sprintf()格式化整个行的方式,将产品信息左对齐,字段最大尺寸,将价格右对齐。
$texttoprint .= sprintf('%s %f', $article, $price); // very basic start: A string and a float
$texttoprint .= sprintf('%-30.30s %8.2f', $article, $price);
// 30 chars for the string, will not exceed this length, and 8 chars for the price, with decimal dot and 2 decimal digits.
Run Code Online (Sandbox Code Playgroud)
请注意,您不应使用stripslashes()最终结果。如果您对斜杠存在疑问,请使用“魔术引号”将其引入,并应在开始时(而不是在结尾处)将其消除。
另一种解决方案是将打印机切换到“ Windows”模式,并使他需要CR / LF才能完成整个行的打印输出。这样,您仅打印CR就可以打印整个行而无需移动纸张,这将使打印机头再次移至行的开头。然后,您可以再次在已打印行的顶部打印,直到打印LF。请注意,如果涉及到实际的打印机头,这可能会使情况变得更糟,因为它可能会触发仅打印一行的额外头移动。打印机通常能够优化一行一行的打印头移动。
| 归档时间: |
|
| 查看次数: |
6080 次 |
| 最近记录: |