\href{https://travis-ci.org/mike42/escpos-php}{\tt !\mbox{[}Build Status\mbox{]}(https\+://travis-\/ci.\+org/mike42/escpos-\/php.\+svg?branch=master)} \href{https://packagist.org/packages/mike42/escpos-php}{\tt !\mbox{[}Latest Stable Version\mbox{]}(https\+://poser.\+pugx.\+org/mike42/escpos-\/php/v/stable)} \href{https://packagist.org/packages/mike42/escpos-php}{\tt !\mbox{[}Total Downloads\mbox{]}(https\+://poser.\+pugx.\+org/mike42/escpos-\/php/downloads)} \href{https://packagist.org/packages/mike42/escpos-php}{\tt !\mbox{[}License\mbox{]}(https\+://poser.\+pugx.\+org/mike42/escpos-\/php/license)} \href{https://coveralls.io/github/mike42/escpos-php?branch=development}{\tt !\mbox{[}Coverage Status\mbox{]}(https\+://coveralls.\+io/repos/github/mike42/escpos-\/php/badge.\+svg?branch=development)}

This project implements a subset of Epson's E\+S\+C/\+P\+O\+S protocol for thermal receipt printers. It allows you to generate and print receipts with basic formatting, cutting, and barcodes on a compatible printer.

The library was developed to add drop-\/in support for receipt printing to any P\+H\+P app, including web-\/based point-\/of-\/sale (P\+O\+S) applications.

\subsection*{Compatibility}

\subsubsection*{Interfaces and operating systems}

This driver is known to work with the following O\+S/interface combinations\+:

\begin{TabularC}{4}
\hline
\rowcolor{lightgray}{\bf ~ }&{\bf Linux }&{\bf Mac }&{\bf Windows  }\\\cline{1-4}
\rowcolor{lightgray}{\bf Ethernet }&\href{https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php}{\tt Yes} &\href{https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php}{\tt Yes} &\href{https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php}{\tt Yes}  \\\cline{1-4}
\rowcolor{lightgray}{\bf U\+S\+B }&\href{https://github.com/mike42/escpos-php/tree/master/example/interface/linux-usb.php}{\tt Yes} &Not tested &\href{https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php}{\tt Yes}  \\\cline{1-4}
\rowcolor{lightgray}{\bf U\+S\+B-\/serial }&Yes &Yes &Yes  \\\cline{1-4}
\rowcolor{lightgray}{\bf Serial }&Yes &Yes &Yes  \\\cline{1-4}
\rowcolor{lightgray}{\bf Parallel }&\href{https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php}{\tt Yes} &Not tested &Yes  \\\cline{1-4}
\rowcolor{lightgray}{\bf S\+M\+B shared }&\href{https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php}{\tt Yes} &No &\href{https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php}{\tt Yes}  \\\cline{1-4}
\rowcolor{lightgray}{\bf C\+U\+P\+S hosted }&\href{https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php}{\tt Yes} &\href{https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php}{\tt Yes} &No  \\\cline{1-4}
\end{TabularC}


\subsubsection*{Printers}

Many thermal receipt printers support E\+S\+C/\+P\+O\+S to some degree. This driver has been known to work with\+:


\begin{DoxyItemize}
\item 3n\+Strat P\+O\+S-\/08
\item A\+U\+R\+E\+S O\+D\+P-\/333
\item A\+U\+R\+E\+S O\+D\+P-\/500
\item Bematech-\/4200-\/\+T\+H
\item Bematech L\+R2000\+E
\item Bixolon S\+R\+P-\/350\+I\+I\+I
\item Black Copper B\+C-\/85\+A\+C
\item Citizen C\+B\+M1000-\/\+I\+I
\item Citizen C\+T-\/\+S310\+I\+I
\item Dapper-\/\+Geyi Q583\+P
\item Daruma D\+R800
\item D\+R-\/\+M\+P200 (manufacturer unknown)
\item E\+P\+O\+S T\+E\+P 220\+M
\item Epson E\+U-\/\+T332\+C
\item Epson F\+X-\/890 (requires {\ttfamily feed\+Form()} to release paper).
\item Epson T\+M-\/\+T20
\item Epson T\+M-\/\+T20\+I\+I
\item Epson T\+M-\/\+T70
\item Epson T\+M-\/\+T70\+I\+I
\item Epson T\+M-\/\+T81
\item Epson T\+M-\/\+T82\+I\+I
\item Epson T\+M-\/\+T88\+I\+I
\item Epson T\+M-\/\+T88\+I\+I\+I
\item Epson T\+M-\/\+T88\+I\+V
\item Epson T\+M-\/\+T88\+V
\item Epson T\+M-\/\+U220
\item Epson T\+M-\/\+U295 (requires {\ttfamily release()} to release slip).
\item Epson T\+M-\/\+U590 and T\+M-\/\+U590\+P
\item Equal (E\+Q-\/\+I\+T-\/001) P\+O\+S-\/58
\item Excelvan H\+O\+P-\/\+E200
\item Excelvan H\+O\+P-\/\+E58
\item Excelvan H\+O\+P-\/\+E801
\item Excelvan Z\+J-\/8220
\item Gainscha G\+P-\/5890x (Also marketed as E\+C Line 5890x)
\item Gainscha G\+P-\/\+U80300\+I (Also marketed as gprinter G\+P-\/\+U80300\+I)
\item gprinter G\+P-\/\+U80160\+I
\item Hasar H\+T\+P 250
\item Metapace T-\/1
\item Metapace T-\/25
\item Nexa P\+X700
\item Nyear N\+P100
\item Okipos 80 Plus I\+I\+I
\item Orient B\+T\+P-\/\+R580
\item Partner Tech R\+P320
\item P-\/822\+D
\item P85\+A-\/401 (make unknown)
\item Rongta R\+P326\+U\+S
\item Rongta R\+P58-\/\+U
\item Senor T\+P-\/100
\item S\+E\+Y\+P\+O\+S P\+R\+P-\/300 (Also marketed as T\+Y\+S\+S\+O P\+R\+P-\/300)
\item Sicar P\+O\+S-\/80
\item Silicon S\+P-\/201 / R\+P80\+U\+S\+E
\item S\+P\+R\+T S\+P-\/\+P\+O\+S88\+V
\item Star B\+S\+C10
\item Star T\+S\+P100 E\+C\+O
\item Star T\+S\+P100\+I\+I\+I Future\+P\+R\+N\+T
\item Star T\+S\+P-\/650
\item Star T\+U\+P-\/592
\item Venus V248\+T
\item Xprinter F-\/900
\item Xprinter X\+P-\/365\+B
\item Xprinter X\+P-\/58 Series
\item Xprinter X\+P-\/80\+C
\item Xprinter X\+P-\/90
\item X\+Printer X\+P-\/\+Q20011
\item Xprinter X\+P-\/\+Q800
\item Zjiang N\+T-\/58\+H
\item Zjiang Z\+J-\/5870
\item Zjiang Z\+J-\/5890\+K
\item Zjiang Z\+J-\/5890\+T (Marketed as P\+O\+S 5890\+T)
\item Zjiang Z\+J-\/8220
\end{DoxyItemize}

If you use any other printer with this code, please \href{https://github.com/mike42/escpos-php/issues/new}{\tt let us know} so that it can be added to the list.

\subsection*{Basic usage}

\subsubsection*{Include the library}

\paragraph*{Composer}

If you are using composer, then add {\ttfamily mike42/escpos-\/php} as a dependency\+:

```bash composer require mike42/escpos-\/php ```

In this case, you would include composer's auto-\/loader at the top of your source files\+:

```php $<$?php require {\bfseries D\+I\+R} . '/vendor/autoload.php'; ```

\paragraph*{Manually}

If you don't have composer available, then simply download the code and include {\ttfamily autoload.\+php}\+:

```bash git clone \href{https://github.com/mike42/escpos-php}{\tt https\+://github.\+com/mike42/escpos-\/php} vendor/mike42/escpos-\/php ```

```php $<$?php require {\bfseries D\+I\+R} . '/vendor/mike42/escpos-\/php/autoload.php'; ```

\paragraph*{Requirements}

To maintain compatibility with as many systems as possible, this driver has few hard dependencies\+:


\begin{DoxyItemize}
\item P\+H\+P 5.\+4 or above.
\item {\ttfamily mbstring} extension, since the driver accepts U\+T\+F-\/8 encoding.
\end{DoxyItemize}

It is also suggested that you install either {\ttfamily imagick} or {\ttfamily gd}, so that you can print images.

A number of optional packages can be added to enable more specific features. These are described in the \char`\"{}suggest\char`\"{} section of \href{https://github.com/mike42/escpos-php/tree/master/composer.json}{\tt composer.\+json}.

\subsubsection*{The 'Hello World' receipt}

To make use of this driver, your server (where P\+H\+P is installed) must be able to communicate with your printer. Start by generating a simple receipt and sending it to your printer using the command-\/line.

```php $<$?php /$\ast$ Call this file 'hello-\/world.\+php' $\ast$/ require {\bfseries D\+I\+R} . '/vendor/autoload.php'; use Mike42; use Mike42; \$connector = new File\+Print\+Connector(\char`\"{}php\+://stdout\char`\"{}); \$printer = new Printer(\$connector); \$printer -\/$>$ text(\char`\"{}\+Hello World!\textbackslash{}n\char`\"{}); \$printer -\/$>$ cut(); \$printer -\/$>$ close(); ```

Some examples are below for common interfaces.

Communicate with a printer with an Ethernet interface using {\ttfamily netcat}\+:

```bash php hello-\/world.\+php $\vert$ nc 10.\+x.\+x.\+x. 9100 ```

A U\+S\+B local printer connected with {\ttfamily usblp} on Linux has a device file (Includes U\+S\+B-\/parallel interfaces)\+:

```bash php hello-\/world.\+php $>$ /dev/usb/lp0 ```

A computer installed into the local {\ttfamily cups} server is accessed through {\ttfamily lp} or {\ttfamily lpr}\+:

```bash php hello-\/world.\+php $>$ foo.\+txt lpr -\/o raw -\/\+H localhost -\/\+P printer foo.\+txt ```

A local or networked printer on a Windows computer is mapped in to a file, and generally requires you to share the printer first\+:

``` php hello-\/world.\+php $>$ foo.\+txt net use L\+P\+T1 \textbackslash{}server copy foo.\+txt L\+P\+T1 del foo.\+txt ```

If you have troubles at this point, then you should consult your O\+S and printer system documentation to try to find a working print command.

\subsubsection*{Using a Print\+Connector}

To print receipts from P\+H\+P, use the most applicable \href{https://github.com/mike42/escpos-php/tree/master/src/Mike42/Escpos/PrintConnectors}{\tt Print\+Connector} for your setup. The connector simply provides the plumbing to get data to the printer.

For example, a {\ttfamily Network\+Print\+Connector} accepts an I\+P address and port\+:

```php use Mike42; use Mike42; \$connector = new Network\+Print\+Connector(\char`\"{}10.\+x.\+x.\+x\char`\"{}, 9100); \$printer = new Printer(\$connector); try \{ // ... Print stuff \} finally \{ \$printer -\/$>$ close(); \} ```

While a serial printer might use\+: ```php use Mike42; use Mike42; \$connector = new File\+Print\+Connector(\char`\"{}/dev/tty\+S0\char`\"{}); \$printer = new Printer(\$connector); ```

For each O\+S/interface combination that's supported, there are examples in the compatibility section of how a {\ttfamily Print\+Connector} would be constructed. If you can't get a {\ttfamily Print\+Connector} to work, then be sure to include the working print command in bug.

\subsubsection*{Using a Capability\+Profile}

Support for commands and code pages varies between printer vendors and models. By default, the driver will accept U\+T\+F-\/8, and output commands that are suitable for Epson T\+M-\/series printers.

When trying out a new brand of printer, it's a good idea to use the \char`\"{}simple\char`\"{} {\ttfamily Capability\+Profile}, which instructs the driver to avoid the use of advanced features (generally simpler image handling, A\+S\+C\+I\+I-\/only text).

```php use Mike42; use Mike42; \$profile = Capability\+Profile\+::load(\char`\"{}simple\char`\"{}); \$connector = new Windows\+Print\+Connector(\char`\"{}smb\+://computer/printer\char`\"{}); \$printer = new Printer(\$connector, \$profile); ```

As another example, Star-\/branded printers use different commands\+:

```php use Mike42; use Mike42; \$profile = Capability\+Profile\+::load(\char`\"{}\+S\+P2000\char`\"{}) \$connector = new Windows\+Print\+Connector(\char`\"{}smb\+://computer/printer\char`\"{}); \$printer = new Printer(\$connector, \$profile); ```

For a list of available profiles, or to have support for your printer improved, please see the upstream \href{https://github.com/receipt-print-hq/escpos-printer-db}{\tt receipt-\/print-\/hq/escpos-\/printer-\/db} project.

\subsubsection*{Tips \& examples}

On Linux, your printer device file will be somewhere like {\ttfamily /dev/lp0} (parallel), {\ttfamily /dev/usb/lp1} (U\+S\+B), {\ttfamily /dev/tty\+U\+S\+B0} (U\+S\+B-\/\+Serial), {\ttfamily /dev/tty\+S0} (serial).

On Windows, the device files will be along the lines of {\ttfamily L\+P\+T1} (parallel) or {\ttfamily C\+O\+M1} (serial). Use the {\ttfamily Windows\+Print\+Connector} to tap into system printing on Windows (eg. \href{https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php}{\tt Windows U\+S\+B}, \href{https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php}{\tt S\+M\+B} or \href{https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php}{\tt Windows L\+P\+T}) -\/ this submits print jobs via a queue rather than communicating directly with the printer.

A complete real-\/world receipt can be found in the code of \href{https://github.com/mike42/Auth}{\tt Auth} in \href{https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php}{\tt Receipt\+Printer.\+php}. It includes justification, boldness, and a barcode.

Other examples are located in the \href{https://github.com/mike42/escpos-php/blob/master/example/}{\tt example/} directory.

\subsection*{Available methods}

\subsubsection*{\+\_\+\+\_\+construct(Print\+Connector \$connector, Capability\+Profile \$profile)}

Construct new print object.

Parameters\+:
\begin{DoxyItemize}
\item {\ttfamily Print\+Connector \$connector}\+: The Print\+Connector to send data to.
\item {\ttfamily Capability\+Profile \$profile} Supported features of this printer. If not set, the \char`\"{}default\char`\"{} Capability\+Profile will be used, which is suitable for Epson printers.
\end{DoxyItemize}

See \href{https://github.com/mike42/escpos-php/tree/master/example/interface/}{\tt example/interface/} for ways to open connections for different platforms and interfaces.

\subsubsection*{barcode(\$content, \$type)}

Print a barcode.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily string \$content}\+: The information to encode.
\item {\ttfamily int \$type}\+: The barcode standard to output. If not specified, {\ttfamily Printer\+::\+B\+A\+R\+C\+O\+D\+E\+\_\+\+C\+O\+D\+E39} will be used.
\end{DoxyItemize}

Currently supported barcode standards are (depending on your printer)\+:


\begin{DoxyItemize}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+U\+P\+C\+A}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+U\+P\+C\+E}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+J\+A\+N13}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+J\+A\+N8}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+C\+O\+D\+E39}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+I\+T\+F}
\item {\ttfamily B\+A\+R\+C\+O\+D\+E\+\_\+\+C\+O\+D\+A\+B\+A\+R}
\end{DoxyItemize}

Note that some barcode standards can only encode numbers, so attempting to print non-\/numeric codes with them may result in strange behaviour.

\subsubsection*{bit\+Image(Escpos\+Image \$image, \$size)}

See \href{#graphicsescposimage-image-size}{\tt graphics()} below.

\subsubsection*{cut(\$mode, \$lines)}

Cut the paper.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$mode}\+: Cut mode, either {\ttfamily Printer\+::\+C\+U\+T\+\_\+\+F\+U\+L\+L} or {\ttfamily Printer\+::\+C\+U\+T\+\_\+\+P\+A\+R\+T\+I\+A\+L}. If not specified, {\ttfamily Printer\+::\+C\+U\+T\+\_\+\+F\+U\+L\+L} will be used.
\item {\ttfamily int \$lines}\+: Number of lines to feed before cutting. If not specified, 3 will be used.
\end{DoxyItemize}

\subsubsection*{feed(\$lines)}

Print and feed line / Print and feed n lines.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$lines}\+: Number of lines to feed
\end{DoxyItemize}

\subsubsection*{feed\+Form()}

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.

\subsubsection*{feed\+Reverse(\$lines)}

Print and reverse feed n lines.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$lines}\+: number of lines to feed. If not specified, 1 line will be fed.
\end{DoxyItemize}

\subsubsection*{graphics(Escpos\+Image \$image, \$size)}

Print an image to the printer.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily Escpos\+Image \$img}\+: The image to print.
\item {\ttfamily int \$size}\+: Output size modifier for the image.
\end{DoxyItemize}

Size modifiers are\+:


\begin{DoxyItemize}
\item {\ttfamily I\+M\+G\+\_\+\+D\+E\+F\+A\+U\+L\+T} (leave image at original size)
\item {\ttfamily I\+M\+G\+\_\+\+D\+O\+U\+B\+L\+E\+\_\+\+W\+I\+D\+T\+H}
\item {\ttfamily I\+M\+G\+\_\+\+D\+O\+U\+B\+L\+E\+\_\+\+H\+E\+I\+G\+H\+T}
\end{DoxyItemize}

A minimal example\+:

```php $<$?php \$img = Escpos\+Image\+::load(\char`\"{}logo.\+png\char`\"{}); \$printer -\/$>$ graphics(\$img); ```

See the \href{https://github.com/mike42/escpos-php/blob/master/example/}{\tt example/} folder for detailed examples.

The function \href{#bitimageescposimage-image-size}{\tt bit\+Image()} takes the same parameters, and can be used if your printer doesn't support the newer graphics commands. As an additional fallback, the {\ttfamily bit\+Image\+Column\+Format()} function is also provided.

\subsubsection*{initialize()}

Initialize printer. This resets formatting back to the defaults.

\subsubsection*{pdf417\+Code(\$content, \$width, \$height\+Multiplier, \$data\+Column\+Count, \$ec, \$options)}

Print a two-\/dimensional data code using the P\+D\+F417 standard.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily string \$content}\+: Text or numbers to store in the code
\item {\ttfamily number \$width}\+: Width of a module (pixel) in the printed code. Default is 3 dots.
\item {\ttfamily number \$height\+Multiplier}\+: Multiplier for height of a module. Default is 3 times the width.
\item {\ttfamily number \$data\+Column\+Count}\+: Number of data columns to use. 0 (default) is to auto-\/calculate. Smaller numbers will result in a narrower code, making larger pixel sizes possible. Larger numbers require smaller pixel sizes.
\item {\ttfamily real \$ec}\+: Error correction ratio, from 0.\+01 to 4.\+00. Default is 0.\+10 (10\%).
\item {\ttfamily number \$options}\+: Standard code {\ttfamily Printer\+::\+P\+D\+F417\+\_\+\+S\+T\+A\+N\+D\+A\+R\+D} with start/end bars, or truncated code {\ttfamily Printer\+::\+P\+D\+F417\+\_\+\+T\+R\+U\+N\+C\+A\+T\+E\+D} with start bars only.
\end{DoxyItemize}

\subsubsection*{pulse(\$pin, \$on\+\_\+ms, \$off\+\_\+ms)}

Generate a pulse, for opening a cash drawer if one is connected. The default settings (0, 120, 240) should open an Epson drawer.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$pin}\+: 0 or 1, for pin 2 or pin 5 kick-\/out connector respectively.
\item {\ttfamily int \$on\+\_\+ms}\+: pulse O\+N time, in milliseconds.
\item {\ttfamily int \$off\+\_\+ms}\+: pulse O\+F\+F time, in milliseconds.
\end{DoxyItemize}

\subsubsection*{qr\+Code(\$content, \$ec, \$size, \$model)}

Print the given data as a Q\+R code on the printer.


\begin{DoxyItemize}
\item {\ttfamily string \$content}\+: The content of the code. Numeric data will be more efficiently compacted.
\item {\ttfamily int \$ec} Error-\/correction level to use. One of {\ttfamily Printer\+::\+Q\+R\+\_\+\+E\+C\+L\+E\+V\+E\+L\+\_\+\+L} (default), {\ttfamily Printer\+::\+Q\+R\+\_\+\+E\+C\+L\+E\+V\+E\+L\+\_\+\+M}, {\ttfamily Printer\+::\+Q\+R\+\_\+\+E\+C\+L\+E\+V\+E\+L\+\_\+\+Q} or {\ttfamily Printer\+::\+Q\+R\+\_\+\+E\+C\+L\+E\+V\+E\+L\+\_\+\+H}. Higher error correction results in a less compact code.
\item {\ttfamily int \$size}\+: Pixel size to use. Must be 1-\/16 (default 3)
\item {\ttfamily int \$model}\+: Q\+R code model to use. Must be one of {\ttfamily Printer\+::\+Q\+R\+\_\+\+M\+O\+D\+E\+L\+\_\+1}, {\ttfamily Printer\+::\+Q\+R\+\_\+\+M\+O\+D\+E\+L\+\_\+2} (default) or {\ttfamily Printer\+::\+Q\+R\+\_\+\+M\+I\+C\+R\+O} (not supported by all printers).
\end{DoxyItemize}

\subsubsection*{select\+Print\+Mode(\$mode)}

Select print mode(s).

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$mode}\+: The mode to use. Default is {\ttfamily Printer\+::\+M\+O\+D\+E\+\_\+\+F\+O\+N\+T\+\_\+\+A}, with no special formatting. This has a similar effect to running {\ttfamily initialize()}.
\end{DoxyItemize}

Several M\+O\+D\+E\+\_\+$\ast$ constants can be O\+R'd together passed to this function's {\ttfamily \$mode} argument. The valid modes are\+:


\begin{DoxyItemize}
\item {\ttfamily M\+O\+D\+E\+\_\+\+F\+O\+N\+T\+\_\+\+A}
\item {\ttfamily M\+O\+D\+E\+\_\+\+F\+O\+N\+T\+\_\+\+B}
\item {\ttfamily M\+O\+D\+E\+\_\+\+E\+M\+P\+H\+A\+S\+I\+Z\+E\+D}
\item {\ttfamily M\+O\+D\+E\+\_\+\+D\+O\+U\+B\+L\+E\+\_\+\+H\+E\+I\+G\+H\+T}
\item {\ttfamily M\+O\+D\+E\+\_\+\+D\+O\+U\+B\+L\+E\+\_\+\+W\+I\+D\+T\+H}
\item {\ttfamily M\+O\+D\+E\+\_\+\+U\+N\+D\+E\+R\+L\+I\+N\+E}
\end{DoxyItemize}

\subsubsection*{set\+Barcode\+Height(\$height)}

Set barcode height.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$height}\+: Height in dots. If not specified, 8 will be used.
\end{DoxyItemize}

\subsubsection*{set\+Barcode\+Width(\$width)}

Set barcode bar width.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$width}\+: Bar width in dots. If not specified, 3 will be used. Values above 6 appear to have no effect.
\end{DoxyItemize}

\subsubsection*{set\+Color(\$color)}

Select print color -\/ on printers that support multiple colors.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$color}\+: Color to use. Must be either {\ttfamily Printer\+::\+C\+O\+L\+O\+R\+\_\+1} (default), or {\ttfamily Printer\+::\+C\+O\+L\+O\+R\+\_\+2}
\end{DoxyItemize}

\subsubsection*{set\+Double\+Strike(\$on)}

Turn double-\/strike mode on/off.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily boolean \$on}\+: true for double strike, false for no double strike.
\end{DoxyItemize}

\subsubsection*{set\+Emphasis(\$on)}

Turn emphasized mode on/off.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily boolean \$on}\+: true for emphasis, false for no emphasis.
\end{DoxyItemize}

\subsubsection*{set\+Font(\$font)}

Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C).

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$font}\+: The font to use. Must be either {\ttfamily Printer\+::\+F\+O\+N\+T\+\_\+\+A}, {\ttfamily Printer\+::\+F\+O\+N\+T\+\_\+\+B}, or {\ttfamily Printer\+::\+F\+O\+N\+T\+\_\+\+C}.
\end{DoxyItemize}

\subsubsection*{set\+Justification(\$justification)}

Select justification.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$justification}\+: One of {\ttfamily Printer\+::\+J\+U\+S\+T\+I\+F\+Y\+\_\+\+L\+E\+F\+T}, {\ttfamily Printer\+::\+J\+U\+S\+T\+I\+F\+Y\+\_\+\+C\+E\+N\+T\+E\+R}, or {\ttfamily Printer\+::\+J\+U\+S\+T\+I\+F\+Y\+\_\+\+R\+I\+G\+H\+T}.
\end{DoxyItemize}

\subsubsection*{set\+Line\+Spacing(\$height)}

Set the height of the line.

Some printers will allow you to overlap lines with a smaller line feed.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$height}\+: The height of each line, in dots. If not set, the printer will reset to its default line spacing.
\end{DoxyItemize}

\subsubsection*{set\+Print\+Left\+Margin(\$margin)}

Set print area left margin. Reset to default with {\ttfamily Printer\+::initialize()}.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$margin}\+: The left margin to set on to the print area, in dots.
\end{DoxyItemize}

\subsubsection*{set\+Print\+Width(\$width)}

Set print area width. This can be used to add a right margin to the print area. Reset to default with {\ttfamily Printer\+::initialize()}.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$width}\+: The width of the page print area, in dots.
\end{DoxyItemize}

\subsubsection*{set\+Reverse\+Colors(\$on)}

Set black/white reverse mode on or off. In this mode, text is printed white on a black background.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily boolean \$on}\+: True to enable, false to disable.
\end{DoxyItemize}

\subsubsection*{set\+Text\+Size(\$width\+Multiplier, \$height\+Multiplier)}

Set the size of text, as a multiple of the normal size.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$width\+Multiplier}\+: Multiple of the regular height to use (range 1 -\/ 8).
\item {\ttfamily int \$height\+Multiplier}\+: Multiple of the regular height to use (range 1 -\/ 8).
\end{DoxyItemize}

\subsubsection*{set\+Underline(\$underline)}

Set underline for printed text.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily int \$underline}\+: Either {\ttfamily true}/{\ttfamily false}, or one of {\ttfamily Printer\+::\+U\+N\+D\+E\+R\+L\+I\+N\+E\+\_\+\+N\+O\+N\+E}, {\ttfamily Printer\+::\+U\+N\+D\+E\+R\+L\+I\+N\+E\+\_\+\+S\+I\+N\+G\+L\+E} or {\ttfamily Printer\+::\+U\+N\+D\+E\+R\+L\+I\+N\+E\+\_\+\+D\+O\+U\+B\+L\+E}. Defaults to {\ttfamily Printer\+::\+U\+N\+D\+E\+R\+L\+I\+N\+E\+\_\+\+S\+I\+N\+G\+L\+E}.
\end{DoxyItemize}

\subsubsection*{text(\$str)}

Add text to the buffer. Text should either be followed by a line-\/break, or {\ttfamily feed()} should be called after this.

Parameters\+:


\begin{DoxyItemize}
\item {\ttfamily string \$str}\+: The string to print.
\end{DoxyItemize}

\section*{Further notes}

Posts I've written up for people who are learning how to use receipt printers\+:


\begin{DoxyItemize}
\item \href{https://mike42.me/blog/what-is-escpos-and-how-do-i-use-it}{\tt What is E\+S\+C/\+P\+O\+S, and how do I use it?}, which documents the output of {\ttfamily example/demo.\+php}.
\item \href{https://mike42.me/blog/2014-20-26-setting-up-an-epson-receipt-printer}{\tt Setting up an Epson receipt printer}
\item \href{https://mike42.me/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux}{\tt Getting a U\+S\+B receipt printer working on Linux}
\end{DoxyItemize}

\section*{Development}

This code is M\+I\+T licensed, and you are encouraged to contribute any modifications back to the project.

For development, it's suggested that you load {\ttfamily imagick}, {\ttfamily gd} and {\ttfamily Xdebug} P\+H\+P exensions, and install {\ttfamily composer}.

The tests are executed on \href{https://travis-ci.org/mike42/escpos-php}{\tt Travis C\+I} over P\+H\+P 5.\+4, 5.\+5, 5.\+6, 7.\+0, 7.\+1 and 7.\+2, plus the latest L\+T\+S version of H\+H\+V\+M, 3.\+21. Older versions of P\+H\+P are not supported in current releases.

Fetch a copy of this code and load dependencies with composer\+: \begin{DoxyVerb}git clone https://github.com/mike42/escpos-php
cd escpos-php/
composer install
\end{DoxyVerb}


Execute unit tests via {\ttfamily phpunit}\+: \begin{DoxyVerb}php vendor/bin/phpunit --coverage-text
\end{DoxyVerb}


This project uses the P\+S\+R-\/2 standard, which can be checked via \href{https://github.com/squizlabs/PHP_CodeSniffer}{\tt P\+H\+P\+\_\+\+Code\+Sniffer}\+: \begin{DoxyVerb}php vendor/bin/phpcs --standard=psr2 src/ -n
\end{DoxyVerb}


The developer docs are build with \href{https://github.com/doxygen/doxygen}{\tt doxygen}. Re-\/build them to check for documentation warnings\+: \begin{DoxyVerb}make -C doc clean && make -C doc
\end{DoxyVerb}


Pull requests and bug reports welcome. 