Download the PHP package mike42/escpos-php without Composer

On this page you can find all versions of the php package mike42/escpos-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
mike42/escpos-php
Rate from 1 - 5
Rated 5.00 based on 2 reviews

Informations about the package escpos-php

ESC/POS Print Driver for PHP

Build Status Latest Stable Version Total Downloads License Coverage Status

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.

The library was developed to add drop-in support for receipt printing to any PHP app, including web-based point-of-sale (POS) applications.

Compatibility

Interfaces and operating systems

This driver is known to work with the following OS/interface combinations:

  Linux Mac Windows
Ethernet Yes Yes Yes
USB Yes Not tested Yes
USB-serial Yes Yes Yes
Serial Yes Yes Yes
Parallel Yes Not tested Yes
SMB shared Yes No Yes
CUPS hosted Yes Yes No

Printers

Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with:

If you use any other printer with this code, please let us know so that it can be added to the list.

Basic usage

Include the library

Composer

This library is designed for use with the composer PHP dependency manager. Simply add the mike42/escpos-php package to get started:

If you haven't used composer before, you can read about it at getcomposer.org.

Requirements

This project has few hard dependencies:

It is also suggested that you install either imagick or gd, as these can be used to speed up image processing.

A number of optional extensions can be added to enable more specific features. These are described in the "suggest" section of composer.json.

The 'Hello World' receipt

To make use of this driver, your server (where PHP 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.

Some examples are below for common interfaces.

Communicate with a printer with an Ethernet interface using netcat:

A USB local printer connected with usblp on Linux has a device file (Includes USB-parallel interfaces):

A computer installed into the local cups server is accessed through lp or lpr:

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

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

Using a PrintConnector

To print receipts from PHP, use the most applicable PrintConnector for your setup. The connector simply provides the plumbing to get data to the printer.

For example, a NetworkPrintConnector accepts an IP address and port:

While a serial printer might use:

For each OS/interface combination that's supported, there are examples in the compatibility section of how a PrintConnector would be constructed. If you can't get a PrintConnector to work, then be sure to include the working print command in your issue.

Using a CapabilityProfile

Support for commands and code pages varies between printer vendors and models. By default, the driver will accept UTF-8, and output commands that are suitable for Epson TM-series printers.

When trying out a new brand of printer, it's a good idea to use the "simple" CapabilityProfile, which instructs the driver to avoid the use of advanced features (generally simpler image handling, ASCII-only text).

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

For a list of available profiles, or to have support for your printer improved, please see the upstream receipt-print-hq/escpos-printer-db project.

Tips & examples

On Linux, your printer device file will be somewhere like /dev/lp0 (parallel), /dev/usb/lp1 (USB), /dev/ttyUSB0 (USB-Serial), /dev/ttyS0 (serial).

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, SMB or Windows LPT) - 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 Auth in ReceiptPrinter.php. It includes justification, boldness, and a barcode.

Other examples are located in the example/ directory.

Available methods

__construct(PrintConnector $connector, CapabilityProfile $profile)

Construct new print object.

Parameters:

See example/interface/ for ways to open connections for different platforms and interfaces.

barcode($content, $type)

Print a barcode.

Parameters:

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

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

bitImage(EscposImage $image, $size)

See graphics() below.

cut($mode, $lines)

Cut the paper.

Parameters:

feed($lines)

Print and feed line / Print and feed n lines.

Parameters:

feedForm()

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.

feedReverse($lines)

Print and reverse feed n lines.

Parameters:

graphics(EscposImage $image, $size)

Print an image to the printer.

Parameters:

Size modifiers are:

A minimal example:

See the example/ folder for detailed examples.

The function bitImage() takes the same parameters, and can be used if your printer doesn't support the newer graphics commands. As an additional fallback, the bitImageColumnFormat() function is also provided.

initialize()

Initialize printer. This resets formatting back to the defaults.

pdf417Code($content, $width, $heightMultiplier, $dataColumnCount, $ec, $options)

Print a two-dimensional data code using the PDF417 standard.

Parameters:

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:

qrCode($content, $ec, $size, $model)

Print the given data as a QR code on the printer.

selectPrintMode($mode)

Select print mode(s).

Parameters:

Several MODE_* constants can be OR'd together passed to this function's $mode argument. The valid modes are:

setBarcodeHeight($height)

Set barcode height.

Parameters:

setBarcodeWidth($width)

Set barcode bar width.

Parameters:

setColor($color)

Select print color - on printers that support multiple colors.

Parameters:

setDoubleStrike($on)

Turn double-strike mode on/off.

Parameters:

setEmphasis($on)

Turn emphasized mode on/off.

Parameters:

setFont($font)

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

Parameters:

setJustification($justification)

Select justification.

Parameters:

setLineSpacing($height)

Set the height of the line.

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

Parameters:

setPrintLeftMargin($margin)

Set print area left margin. Reset to default with Printer::initialize().

Parameters:

setPrintWidth($width)

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

Parameters:

setReverseColors($on)

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

Parameters:

setTextSize($widthMultiplier, $heightMultiplier)

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

Parameters:

setUnderline($underline)

Set underline for printed text.

Parameters:

text($str)

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

Parameters:

Further notes

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

Development

This code is MIT licensed, and you are encouraged to contribute any modifications back to the project.

For development, it's suggested that you load imagick, gd and Xdebug PHP extensions.

The tests are executed on Travis CI over PHP 7.3, 7.4 and 8.0. Older versions of PHP are not supported in the current release, nor is HHVM.

Fetch a copy of this code and load dependencies with composer:

git clone https://github.com/mike42/escpos-php
cd escpos-php/
composer install

Execute unit tests via phpunit:

php vendor/bin/phpunit --coverage-text

This project uses the PSR-2 standard, which can be checked via PHP_CodeSniffer:

php vendor/bin/phpcs --standard=psr2 src/ -n

The developer docs are build with doxygen. Re-build them to check for documentation warnings:

make -C doc clean && make -C doc

Pull requests and bug reports welcome.


All versions of escpos-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3.0
ext-json Version *
ext-intl Version *
ext-zlib Version *
mike42/gfx-php Version ^0.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mike42/escpos-php contains the following files

Loading the files please wait ....