PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/_librerias/escpos/README.md

https://gitlab.com/IsGaytan/super_morenos_systems_punto_de_venta
Markdown | 352 lines | 260 code | 92 blank | 0 comment | 0 complexity | 20cb397b1d04112a99d8a04b172fa1d1 MD5 | raw file
Possible License(s): MIT
  1. ESC/POS Print Driver for PHP
  2. ============================
  3. This project implements a subset of Epson's ESC/POS protocol for thermal receipt printers. It allows you to generate and print receipts with basic formatting, cutting, and barcodes on a compatible printer.
  4. The library was developed to add drop-in support for receipt printing to any PHP app, including web-based point-of-sale (POS) applications.
  5. Basic usage
  6. -----------
  7. A "hello world" receipt can be generated easily (Call this `hello-world.php`):
  8. ```php
  9. <?php
  10. require_once(dirname(__FILE__) . "/Escpos.php");
  11. $printer = new Escpos();
  12. $printer -> text("Hello World!\n");
  13. $printer -> cut();
  14. $printer -> close();
  15. ```
  16. This would be printed as:
  17. ```
  18. # Networked printer
  19. php hello-world.php | nc 10.x.x.x. 9100
  20. # Local printer
  21. php hello-world.php > /dev/...
  22. # Windows local printer
  23. php hello-world.php > foo.txt
  24. net use LPT1 \\server\printer
  25. copy foo.txt LPT1
  26. del foo.txt
  27. ```
  28. From your web app, you could pass the output directly to a socket if your printer is networked:
  29. ```php
  30. <?php
  31. require_once(dirname(__FILE__) . "/Escpos.php");
  32. $connector = new NetworkPrintConnector("10.x.x.x", 9100);
  33. $printer = new Escpos($connector);
  34. $printer -> text("Hello World!\n");
  35. $printer -> cut();
  36. $printer -> close();
  37. ```
  38. Or to a local printer:
  39. ```php
  40. <?php
  41. require_once(dirname(__FILE__) . "/Escpos.php");
  42. $connector = new FilePrintConnector("/dev/ttyS0");
  43. $printer = new Escpos($connector);
  44. $printer -> text("Hello World!\n");
  45. $printer -> cut();
  46. $printer -> close();
  47. ```
  48. ### Basic workflow
  49. The library should be initialised with a PrintConnector, which will pass on the data to your printer.
  50. Use the table under "Compatibility", or the examples below to choose the appropriate connector for your
  51. platform & interface. If no connector is specified, then standard output is used.
  52. When you have finished using the print object, call `close()` to finalize any data transfers.
  53. ### Tips & examples
  54. On Linux, your printer device file will be somewhere like `/dev/lp0` (parallel), `/dev/usb/lp1` (USB), `/dev/ttyUSB0` (USB-Serial), `/dev/ttyS0` (serial).
  55. On Windows, the device files will be along the lines of `LPT1` (parallel) or `COM1` (serial). Use the `WindowsPrintConnector` to tap into system printing on Windows (eg. [Windows USB](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php), [SMB](https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php) or [Windows LPT](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php)) - this submits print jobs via a queue rather than communicating directly with the printer.
  56. A complete real-world receipt can be found in the code of [Auth](https://github.com/mike42/Auth) in [ReceiptPrinter.php](https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php). It includes justification, boldness, and a barcode.
  57. Other examples are located in the [example/](https://github.com/mike42/escpos-php/blob/master/example/) directory.
  58. Compatibility
  59. -------------
  60. ### Interfaces and operating systems
  61. This driver is known to work with the following OS/interface combinations:
  62. <table>
  63. <tr>
  64. <th>&nbsp;</th>
  65. <th>Linux</th>
  66. <th>Mac</th>
  67. <th>Windows</th>
  68. </tr>
  69. <tr>
  70. <th>Ethernet</th>
  71. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
  72. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
  73. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
  74. </tr>
  75. <tr>
  76. <th>USB</th>
  77. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/linux-usb.php">Yes</a></td>
  78. <td>Not tested</td>
  79. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php">Yes</a></td>
  80. </tr>
  81. <tr>
  82. <th>USB-serial</th>
  83. <td>Yes</td>
  84. <td>Yes</td>
  85. <td>Yes</td>
  86. </tr>
  87. <tr>
  88. <th>Serial</th>
  89. <td>Yes</td>
  90. <td>Yes</td>
  91. <td>Yes</td>
  92. </tr>
  93. <tr>
  94. <th>Parallel</th>
  95. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php">Yes</a></td>
  96. <td>Not tested</td>
  97. <td>Yes</td>
  98. </tr>
  99. <tr>
  100. <th>SMB shared</th>
  101. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
  102. <td>No</td>
  103. <td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
  104. </tr>
  105. </table>
  106. ### Printers
  107. Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with:
  108. - EPOS TEP 220M
  109. - Epson TM-T88III
  110. - Epson TM-T88IV
  111. - Epson TM-T70
  112. - Epson TM-T82II
  113. - Epson TM-T20
  114. - Epson TM-T70II
  115. - Epson TM-U220
  116. - Epson FX-890 (requires `feedForm()` to release paper).
  117. - Okipos 80 Plus III
  118. - P-822D
  119. - SEYPOS PRP-300 (Also marketed as TYSSO PRP-300)
  120. - Star TSP-650
  121. - Star TUP-592
  122. - Xprinter XP-Q800
  123. - Zijang NT-58H
  124. - Zijang ZJ-5870
  125. - Zijang ZJ-5890T (Marketed as POS 5890T)
  126. If you use any other printer with this code, please let me know so I can add it to the list.
  127. Available methods
  128. -----------------
  129. ### __construct(PrintConnector $connector, AbstractCapabilityProfile $profile)
  130. Construct new print object.
  131. Parameters:
  132. - `PrintConnector $connector`: The PrintConnector to send data to. If not set, output is sent to standard output.
  133. - `AbstractCapabilityProfile $profile` Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers.
  134. See [example/interface/]("https://github.com/mike42/escpos-php/tree/master/example/interface/) for ways to open connections for different platforms and interfaces.
  135. ### barcode($content, $type)
  136. Print a barcode.
  137. Parameters:
  138. - `string $content`: The information to encode.
  139. - `int $type`: The barcode standard to output. If not specified, `Escpos::BARCODE_CODE39` will be used.
  140. Currently supported barcode standards are (depending on your printer):
  141. - `BARCODE_UPCA`
  142. - `BARCODE_UPCE`
  143. - `BARCODE_JAN13`
  144. - `BARCODE_JAN8`
  145. - `BARCODE_CODE39`
  146. - `BARCODE_ITF`
  147. - `BARCODE_CODABAR`
  148. Note that some barcode standards can only encode numbers, so attempting to print non-numeric codes with them may result in strange behaviour.
  149. ### bitImage(EscposImage $image, $size)
  150. See [graphics()](#graphicsescposimage-image-size) below.
  151. ### cut($mode, $lines)
  152. Cut the paper.
  153. Parameters:
  154. - `int $mode`: Cut mode, either `Escpos::CUT_FULL` or `Escpos::CUT_PARTIAL`. If not specified, `Escpos::CUT_FULL` will be used.
  155. - `int $lines`: Number of lines to feed before cutting. If not specified, 3 will be used.
  156. ### feed($lines)
  157. Print and feed line / Print and feed n lines.
  158. Parameters:
  159. - `int $lines`: Number of lines to feed
  160. ### feedForm()
  161. Some printers require a form feed to release the paper. On most printers, this command is only useful in page mode, which is not implemented in this driver.
  162. ### feedReverse($lines)
  163. Print and reverse feed n lines.
  164. Parameters:
  165. - `int $lines`: number of lines to feed. If not specified, 1 line will be fed.
  166. ### graphics(EscposImage $image, $size)
  167. Print an image to the printer.
  168. Parameters:
  169. - `EscposImage $img`: The image to print.
  170. - `int $size`: Output size modifier for the image.
  171. Size modifiers are:
  172. - `IMG_DEFAULT` (leave image at original size)
  173. - `IMG_DOUBLE_WIDTH`
  174. - `IMG_DOUBLE_HEIGHT`
  175. A minimal example:
  176. ```php
  177. <?php
  178. $img = new EscposImage("logo.png");
  179. $printer -> graphics($img);
  180. ```
  181. See the [example/](https://github.com/mike42/escpos-php/blob/master/example/) folder for detailed examples.
  182. The function [bitImage()](#bitimageescposimage-image-size) takes the same parameters, and can be used if your printer doesn't support the newer graphics commands.
  183. ### initialize()
  184. Initialize printer. This resets formatting back to the defaults.
  185. ### pulse($pin, $on_ms, $off_ms)
  186. Generate a pulse, for opening a cash drawer if one is connected. The default settings (0, 120, 240) should open an Epson drawer.
  187. Parameters:
  188. - `int $pin`: 0 or 1, for pin 2 or pin 5 kick-out connector respectively.
  189. - `int $on_ms`: pulse ON time, in milliseconds.
  190. - `int $off_ms`: pulse OFF time, in milliseconds.
  191. ### qrCode($content, $ec, $size, $model)
  192. Print the given data as a QR code on the printer.
  193. - `string $content`: The content of the code. Numeric data will be more efficiently compacted.
  194. - `int $ec` Error-correction level to use. One of `Escpos::QR_ECLEVEL_L` (default), `Escpos::QR_ECLEVEL_M`, `Escpos::QR_ECLEVEL_Q` or `Escpos::QR_ECLEVEL_H`. Higher error correction results in a less compact code.
  195. - `int $size`: Pixel size to use. Must be 1-16 (default 3)
  196. - `int $model`: QR code model to use. Must be one of `Escpos::QR_MODEL_1`, `Escpos::QR_MODEL_2` (default) or `Escpos::QR_MICRO` (not supported by all printers).
  197. ### selectPrintMode($mode)
  198. Select print mode(s).
  199. Parameters:
  200. - `int $mode`: The mode to use. Default is `Escpos::MODE_FONT_A`, with no special formatting. This has a similar effect to running `initialize()`.
  201. Several MODE_* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are:
  202. - `MODE_FONT_A`
  203. - `MODE_FONT_B`
  204. - `MODE_EMPHASIZED`
  205. - `MODE_DOUBLE_HEIGHT`
  206. - `MODE_DOUBLE_WIDTH`
  207. - `MODE_UNDERLINE`
  208. ### setBarcodeHeight($height)
  209. Set barcode height.
  210. Parameters:
  211. - `int $height`: Height in dots. If not specified, 8 will be used.
  212. ### setDoubleStrike($on)
  213. Turn double-strike mode on/off.
  214. Parameters:
  215. - `boolean $on`: true for double strike, false for no double strike.
  216. ### setEmphasis($on)
  217. Turn emphasized mode on/off.
  218. Parameters:
  219. - `boolean $on`: true for emphasis, false for no emphasis.
  220. ### setFont($font)
  221. Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C).
  222. Parameters:
  223. - `int $font`: The font to use. Must be either `Escpos::FONT_A`, `Escpos::FONT_B`, or `Escpos::FONT_C`.
  224. ### setJustification($justification)
  225. Select justification.
  226. Parameters:
  227. - `int $justification`: One of `Escpos::JUSTIFY_LEFT`, `Escpos::JUSTIFY_CENTER`, or `Escpos::JUSTIFY_RIGHT`.
  228. ### setReverseColors($on)
  229. Set black/white reverse mode on or off. In this mode, text is printed white on a black background.
  230. Parameters:
  231. - `boolean $on`: True to enable, false to disable.
  232. ### setTextSize($widthMultiplier, $heightMultiplier)
  233. Set the size of text, as a multiple of the normal size.
  234. Parameters:
  235. - `int $widthMultiplier`: Multiple of the regular height to use (range 1 - 8).
  236. - `int $heightMultiplier`: Multiple of the regular height to use (range 1 - 8).
  237. ### setUnderline($underline)
  238. Set underline for printed text.
  239. Parameters:
  240. - `int $underline`: Either `true`/`false`, or one of `Escpos::UNDERLINE_NONE`, `Escpos::UNDERLINE_SINGLE` or `Escpos::UNDERLINE_DOUBLE`. Defaults to `Escpos::UNDERLINE_SINGLE`.
  241. ### text($str)
  242. Add text to the buffer. Text should either be followed by a line-break, or `feed()` should be called after this.
  243. Parameters:
  244. - `string $str`: The string to print.
  245. Further notes
  246. -------------
  247. Posts I've written up for people who are learning how to use receipt printers:
  248. * [What is ESC/POS, and how do I use it?](http://mike.bitrevision.com/blog/what-is-escpos-and-how-do-i-use-it), which documents the output of test.php.
  249. * [Setting up an Epson receipt printer](http://mike.bitrevision.com/blog/2014-20-26-setting-up-an-epson-receipt-printer)
  250. * [Getting a USB receipt printer working on Linux](http://mike.bitrevision.com/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux)
  251. Other versions
  252. --------------
  253. Some forks of this project have been developed by others for specific use cases. Improvements from the following projects have been incorporated into escpos-php:
  254. - [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP)
  255. - [ronisaha/php-esc-pos](https://github.com/ronisaha/php-esc-pos)
  256. Vendor documentation
  257. --------------------
  258. Epson notes that not all of its printers support all ESC/POS features, and includes a table in their documentation:
  259. * [FAQ about ESC/POS from Epson](http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf)
  260. Note that many printers produced by other vendors use the same standard, and are compatible by varying degrees.