有没有办法使用 PHP 打印收据?



我正在尝试这种方式,但它没有产生正确的对齐方式。我正在尝试使用局域网中的网络打印机"HP LaserJet Mono PCLmS 类驱动程序"进行打印。打印工作正常,但对齐并不完美。

$text1 = $this->string_align("Example item #1", "4.00");
$text2 = $this->string_align("Another thing tea", "3.50");
$text3 = $this->string_align("Something else", "1.00");
$text4 = $this->string_align("A final item", "4.45");
$text5 = $this->string_align("Subtotal", "12.95");
$text6 = $this->string_align("A local tax", "1.30");
$text7 = $this->string_align("Grand Total", "14.25");
$handle = printer_open("HP LaserJet Mono PCLmS Class Driver");
printer_start_doc($handle, "Recept Document");
printer_start_page($handle);
printer_draw_bmp($handle, "D:\logo.bmp", 1, 1);
$font = printer_create_font("Arial", 50, 70, 300, false, false, false, 0);
printer_select_font($handle, $font);
printer_draw_text($handle, $text1, 100, 400);
printer_draw_text($handle, $text2, 100, 500);
printer_draw_text($handle, $text3, 100, 600);
printer_draw_text($handle, $text4, 100, 700);
printer_draw_text($handle, $text5, 100, 800);
printer_draw_text($handle, $text6, 100, 900);
printer_draw_text($handle, $text7, 100, 1000);
printer_delete_font($font);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
exit;
function string_align($name = '', $price = '', $dollarSign = false){
$rightCols = 10;
$leftCols = 38;
if ($dollarSign) {
$leftCols = $leftCols / 2 - $rightCols / 2;
}
$left = str_pad($name, $leftCols) ;
$sign = ($dollarSign ? '$ ' : '');
$right = str_pad($sign . $price, $rightCols, ' ', STR_PAD_LEFT);
return "$left$rightn";
}

尝试使用consolas字体。

它是统一宽度的字体,应该在打印页面上正确呈现。

相关内容

  • 没有找到相关文章

最新更新