Esc P Brother QL720NW

时间:2016-03-29 10:20:39

标签: php printing

我正在尝试使用ESC / P语言从php脚本打印到主题的thaermal打印机。当我尝试正常打印文本时,一切都很好,问题是我无法设置字体大小,或者通常是格式化选项。例如,阅读手册我发现,如果我想设置字体大小,我必须使用这些代码:

  
      
  • [ASCII] ESC X m nL nH
  •   
  • [十进制] 27 88 m nL nH
  •   
  • [十六进制] 1B 58 m nL nH
  •   

所以我以这种方式发送了命令:

     Try
            Dim myHttpWebRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://www.example.com"), HttpWebRequest)
            Dim myHttpWebResponse As HttpWebResponse = DirectCast(myHttpWebRequest.GetResponse(), HttpWebResponse)
            myHttpWebResponse.Close()
            ''Some codes
      Catch
            ''Some codes
      End Try

但它打印简洁的文字和数字,而不是理解格式选项。 哪里我错了???

1 个答案:

答案 0 :(得分:2)

由于我没有相同的打印机,我无法评论此命令是否会按预期执行,但确实显示您在命令的每个字节之间包含空格,这是不正确的ESC / P2

reference中的约定似乎是包含要发送的字节的十六进制和十进制代码,而间隔只是为了便于阅读。

遵循这些命令标准的片段是 -

<?php

// Initialize printer
$fp = fopen("/dev/usb/lp0", "wb+");
fwrite ( $fp, "\x1B\x40" ); // ESC @

// Select font by pitch and point
$m = 0; // No change in pitch
$nL = 48; // Assuming these point options are what you intend?
$nH = 128;
fwrite ( $fp, "\x1B\x58" . chr($m) . chr($nL) . chr($nH)); // ESC X m nL nH

// Print text
$stringToPrint = "Hello\n";
fwrite ( $fp, $stringToPrint );

// Form feed
fwrite ( $fp, "\x0C" ); // FF