所以我从我们的网络服务器(也在办公室)打印到办公室的联网热敏打印机,这样客户就可以在网站上下订单,然后他们就会出现在销售部门的办公桌上。这是我使用的代码,它工作得很好。然而,在打印单据上的项目时,我希望项目文本居中对齐,价格文本右对齐,但它不会让我这样做(因为我认为它是同一行)所以我怎么能说换行(\ 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";
...
正如你在这里看到的,最后两个在同一条线上,我试图证明产品中心和价格是正确的。他们最终都居中,如果我在两者之间加上 /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);
}