### Clone escpos-php and Install Dependencies with Composer Source: https://github.com/mike42/escpos-php/blob/development/README.md Fetches a copy of the escpos-php project from GitHub and installs its PHP dependencies using Composer. This is the initial setup step for development. ```Bash git clone https://github.com/mike42/escpos-php cd escpos-php/ composer install ``` -------------------------------- ### Clone Repository and Install PHP Dependencies with Composer Source: https://github.com/mike42/escpos-php/blob/development/CONTRIBUTING.md Instructions to clone the `escpos-php` repository and install its PHP dependencies using Composer, preparing the environment for development. ```Bash git clone https://github.com/mike42/escpos-php cd escpos-php/ composer install ``` -------------------------------- ### Generate a 'Hello World' Receipt with PHP Source: https://github.com/mike42/escpos-php/blob/development/README.md A basic PHP script demonstrating how to initialize the ESC/POS printer driver, print 'Hello World!', cut the paper, and close the connection. This example uses a FilePrintConnector to output to standard output. ```PHP text("Hello World!\n"); $printer -> cut(); $printer -> close(); ``` -------------------------------- ### Install ESC/POS PHP Library with Composer Source: https://github.com/mike42/escpos-php/blob/development/README.md Instructions to add the mike42/escpos-php library to your PHP project using Composer, the PHP dependency manager. ```Bash composer require mike42/escpos-php ``` -------------------------------- ### Send 'Hello World' Receipt to Various Printer Interfaces Source: https://github.com/mike42/escpos-php/blob/development/README.md Examples of command-line commands to send the 'hello-world.php' output to different printer interfaces, including Ethernet (netcat), USB local (Linux), CUPS server (Linux), and shared network printers (Windows). ```Bash php hello-world.php | nc 10.x.x.x. 9100 ``` ```Bash php hello-world.php > /dev/usb/lp0 ``` ```Bash php hello-world.php > foo.txt lpr -o raw -H localhost -P printer foo.txt ``` ```Windows Command Line php hello-world.php > foo.txt net use LPT1 \\server\printer copy foo.txt LPT1 del foo.txt ``` -------------------------------- ### Connect to Serial Printer using FilePrintConnector Source: https://github.com/mike42/escpos-php/blob/development/README.md Example of using `FilePrintConnector` to connect to a serial printer, typically found at a device path like `/dev/ttyS0` on Linux systems. ```PHP use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\Printer; $connector = new FilePrintConnector("/dev/ttyS0"); $printer = new Printer($connector); ``` -------------------------------- ### JavaScript AJAX Function for RawBT Printing Source: https://github.com/mike42/escpos-php/blob/development/example/rawbt-receipt.html Implements an AJAX function `ajax_print` designed to send a GET request to a specified URL, typically a backend endpoint for print data. Upon successful response, it redirects the browser to the received data. The function also provides visual feedback by changing the button text during the request lifecycle. ```JavaScript // for php demo call function ajax_print(url, btn) { b = $(btn); b.attr('data-old', b.text()); b.text('wait'); $.get(url, function (data) { window.location.href = data; // main action }).fail(function () { alert("ajax error"); }).always(function () { b.text(b.attr('data-old')); }) } ``` -------------------------------- ### PHP Printer Class: Print Image (Graphics) Source: https://github.com/mike42/escpos-php/blob/development/README.md Prints an image to the printer using the EscposImage object and an optional size modifier. Supported size modifiers include IMG_DEFAULT, IMG_DOUBLE_WIDTH, and IMG_DOUBLE_HEIGHT. A minimal PHP example demonstrates loading an image and printing it. ```APIDOC graphics(EscposImage $img, int $size) $img: The image to print. $size: Output size modifier for the image. Size modifiers: IMG_DEFAULT, IMG_DOUBLE_WIDTH, IMG_DOUBLE_HEIGHT ``` ```php graphics($img); ``` -------------------------------- ### Execute PHP Unit Tests with PHPUnit Source: https://github.com/mike42/escpos-php/blob/development/CONTRIBUTING.md Command to run the unit tests for the `escpos-php` project using PHPUnit, including text coverage reporting. ```Bash php vendor/bin/phpunit --coverage-text ``` -------------------------------- ### Styling for RawBT Integration Demo Page Source: https://github.com/mike42/escpos-php/blob/development/example/rawbt-receipt.html Defines the basic visual styles for the RawBT integration demo page, including background colors, layout constraints, button appearance, preformatted text styling, and link decorations. ```CSS html { background-color: grey; padding: 32px; } body { max-width: 640px; margin: 0 auto; padding: 32px; background-color: white; } button { background-color: #6e89ff; color: white; padding: 16px; border: none; } pre { background-color: #f0f0f0; border-left: #6e89ff solid 3px } p { text-align: right; } a { color: #6e89ff; text-decoration: none; } a:before{ content: '\1F855'; margin-right:4px; } ``` -------------------------------- ### Rebuild Doxygen Developer Documentation Source: https://github.com/mike42/escpos-php/blob/development/CONTRIBUTING.md Commands to clean and rebuild the developer documentation using Doxygen, allowing for checking of documentation warnings. ```Bash make -C doc clean && make -C doc ``` -------------------------------- ### Execute PHPUnit Unit Tests with Coverage Source: https://github.com/mike42/escpos-php/blob/development/README.md Runs the project's unit tests using PHPUnit, displaying code coverage information. This helps verify the correctness of the code. ```Bash php vendor/bin/phpunit --coverage-text ``` -------------------------------- ### Load 'Simple' CapabilityProfile for Basic Printer Features Source: https://github.com/mike42/escpos-php/blob/development/README.md Illustrates how to load the 'simple' `CapabilityProfile` to instruct the ESC/POS driver to use only basic features, suitable for new or less advanced printer brands, ensuring compatibility with ASCII-only text and simpler image handling. ```PHP use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; use Mike42\Escpos\CapabilityProfile; $profile = CapabilityProfile::load("simple"); $connector = new WindowsPrintConnector("smb://computer/printer"); $printer = new Printer($connector, $profile); ``` -------------------------------- ### JavaScript Browser Redirection for RawBT Data Source: https://github.com/mike42/escpos-php/blob/development/example/rawbt-receipt.html Demonstrates a direct browser redirection using `window.location.href` to a URL or data string provided by `ajax_backend_data`. This is a common pattern for initiating a print action or opening a new resource after an asynchronous operation. ```JavaScript window.location.href = ajax_backend_data; ``` -------------------------------- ### Load 'SP2000' CapabilityProfile for Star Printers Source: https://github.com/mike42/escpos-php/blob/development/README.md Shows how to load a specific `CapabilityProfile`, such as 'SP2000', for Star-branded printers, which require different command sets compared to default Epson TM-series printers. ```PHP use Mike42\Escpos\PrintConnectors\WindowsPrintConnector; use Mike42\Escpos\CapabilityProfile; $profile = CapabilityProfile::load("SP2000"); $connector = new WindowsPrintConnector("smb://computer/printer"); $printer = new Printer($connector, $profile); ``` -------------------------------- ### Connect to Network Printer using NetworkPrintConnector Source: https://github.com/mike42/escpos-php/blob/development/README.md Demonstrates how to establish a connection to an ESC/POS printer over a network using the `NetworkPrintConnector` class, specifying an IP address and port. Includes error handling with a `try...finally` block to ensure the printer connection is closed. ```PHP use Mike42\Escpos\PrintConnectors\NetworkPrintConnector; use Mike42\Escpos\Printer; $connector = new NetworkPrintConnector("10.x.x.x", 9100); $printer = new Printer($connector); try { // ... Print stuff } finally { $printer -> close(); } ``` -------------------------------- ### Rebuild Developer Documentation with Doxygen Source: https://github.com/mike42/escpos-php/blob/development/README.md Cleans and rebuilds the developer documentation using Doxygen. This step is important to check for documentation warnings and ensure the docs are up-to-date. ```Bash make -C doc clean && make -C doc ``` -------------------------------- ### PHP Printer Class Constructor Source: https://github.com/mike42/escpos-php/blob/development/README.md Constructs a new Printer object, initializing it with a PrintConnector for data transmission and an optional CapabilityProfile to define supported printer features. If no profile is provided, a default suitable for Epson printers is used. ```APIDOC __construct(PrintConnector $connector, CapabilityProfile $profile) $connector: The PrintConnector to send data to. $profile: Supported features of this printer. If not set, the "default" CapabilityProfile will be used, which is suitable for Epson printers. ``` -------------------------------- ### Check PHP Code Style with PHP_CodeSniffer (PSR-2) Source: https://github.com/mike42/escpos-php/blob/development/CONTRIBUTING.md Command to check the PHP code style against the PSR-2 standard using PHP_CodeSniffer, specifically for the `src/` directory, without fixing issues. ```Bash php vendor/bin/phpcs --standard=psr2 src/ -n ``` -------------------------------- ### PHP Printer Class: Initialize Printer Source: https://github.com/mike42/escpos-php/blob/development/README.md Resets the printer's formatting settings back to their default values. This is useful for ensuring a clean state before printing new content. ```APIDOC initialize() ``` -------------------------------- ### PHP ESC/POS: Select Print Mode Source: https://github.com/mike42/escpos-php/blob/development/README.md Selects various print modes for text formatting, such as font, emphasis, and size. Multiple modes can be combined using bitwise OR. ```APIDOC selectPrintMode(int $mode) $mode: The mode to use. Default is Printer::MODE_FONT_A, with no special formatting. This has a similar effect to running initialize(). Valid modes (can be OR'd): MODE_FONT_A MODE_FONT_B MODE_EMPHASIZED MODE_DOUBLE_HEIGHT MODE_DOUBLE_WIDTH MODE_UNDERLINE ``` -------------------------------- ### Check PHP PSR-2 Coding Standard with PHP_CodeSniffer Source: https://github.com/mike42/escpos-php/blob/development/README.md Verifies that the PHP source code adheres to the PSR-2 coding standard using PHP_CodeSniffer. This ensures code consistency and readability. ```Bash php vendor/bin/phpcs --standard=psr2 src/ -n ``` -------------------------------- ### PHP ESC/POS: Print QR Code Source: https://github.com/mike42/escpos-php/blob/development/README.md Prints a QR code on the printer with specified content, error correction level, pixel size, and model. Numeric data is more efficiently compacted. ```APIDOC qrCode(string $content, int $ec, int $size, int $model) $content: The content of the code. Numeric data will be more efficiently compacted. $ec: Error-correction level to use. One of Printer::QR_ECLEVEL_L (default), Printer::QR_ECLEVEL_M, Printer::QR_ECLEVEL_Q or Printer::QR_ECLEVEL_H. Higher error correction results in a less compact code. $size: Pixel size to use. Must be 1-16 (default 3) $model: QR code model to use. Must be one of Printer::QR_MODEL_1, Printer::QR_MODEL_2 (default) or Printer::QR_MICRO (not supported by all printers). ``` -------------------------------- ### PHP ESC/POS: Select Font Source: https://github.com/mike42/escpos-php/blob/development/README.md Selects the font to be used for printing. Most printers support Font A and B, some also Font C. ```APIDOC setFont(int $font) $font: The font to use. Must be either Printer::FONT_A, Printer::FONT_B, or Printer::FONT_C. ``` -------------------------------- ### PHP ESC/POS: Generate Cash Drawer Pulse Source: https://github.com/mike42/escpos-php/blob/development/README.md Generates a pulse to open a cash drawer connected to the printer. Configurable for specific pins and pulse timings. ```APIDOC pulse(int $pin, int $on_ms, int $off_ms) $pin: 0 or 1, for pin 2 or pin 5 kick-out connector respectively. $on_ms: pulse ON time, in milliseconds. $off_ms: pulse OFF time, in milliseconds. ``` -------------------------------- ### PHP Printer Class: Print Bit Image (Fallback) Source: https://github.com/mike42/escpos-php/blob/development/README.md This method is a fallback for printing images, taking an EscposImage object and a size modifier. It is superseded by the `graphics()` method for newer printers. An additional fallback, `bitImageColumnFormat()`, is also available. ```APIDOC bitImage(EscposImage $image, $size) See graphics() for parameters. ``` -------------------------------- ### PHP ESC/POS: Select Text Justification Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the horizontal alignment for printed text (left, center, or right). ```APIDOC setJustification(int $justification) $justification: One of Printer::JUSTIFY_LEFT, Printer::JUSTIFY_CENTER, or Printer::JUSTIFY_RIGHT. ``` -------------------------------- ### PHP ESC/POS: Toggle Reverse Color Mode Source: https://github.com/mike42/escpos-php/blob/development/README.md Enables or disables reverse color mode, printing white text on a black background. ```APIDOC setReverseColors(boolean $on) $on: True to enable, false to disable. ``` -------------------------------- ### PHP Printer Class: Form Feed Source: https://github.com/mike42/escpos-php/blob/development/README.md Performs a form feed command, which is required by some printers to release paper. This command is primarily useful in page mode, which is not implemented in this driver. ```APIDOC feedForm() ``` -------------------------------- ### PHP Printer Class: Reverse Feed Lines Source: https://github.com/mike42/escpos-php/blob/development/README.md Feeds the printer paper in reverse by a specified number of lines. If no number is specified, it defaults to one line. ```APIDOC feedReverse(int $lines) $lines: Number of lines to feed. If not specified, 1 line will be fed. ``` -------------------------------- ### PHP ESC/POS: Select Print Color Source: https://github.com/mike42/escpos-php/blob/development/README.md Selects the print color on printers that support multiple colors. Defaults to COLOR_1. ```APIDOC setColor(int $color) $color: Color to use. Must be either Printer::COLOR_1 (default), or Printer::COLOR_2 ``` -------------------------------- ### PHP Printer Class: Feed Lines Source: https://github.com/mike42/escpos-php/blob/development/README.md Feeds the printer paper by a specified number of lines. This is used to advance the paper after printing. ```APIDOC feed(int $lines) $lines: Number of lines to feed ``` -------------------------------- ### PHP Printer Class: Cut Paper Source: https://github.com/mike42/escpos-php/blob/development/README.md Cuts the printer paper, allowing for full or partial cuts. The method also specifies the number of lines to feed before performing the cut. Default cut mode is full, and default lines to feed is 3. ```APIDOC cut(int $mode, int $lines) $mode: Cut mode, either Printer::CUT_FULL or Printer::CUT_PARTIAL. If not specified, Printer::CUT_FULL will be used. $lines: Number of lines to feed before cutting. If not specified, 3 will be used. ``` -------------------------------- ### PHP ESC/POS: Set Line Spacing Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the height of each line in dots. Smaller values can cause lines to overlap on some printers. ```APIDOC setLineSpacing(int $height) $height: The height of each line, in dots. If not set, the printer will reset to its default line spacing. ``` -------------------------------- ### PHP ESC/POS: Add Text to Buffer Source: https://github.com/mike42/escpos-php/blob/development/README.md Adds a string of text to the printer's buffer. A line-break or `feed()` call is typically required afterwards. ```APIDOC text(string $str) $str: The string to print. ``` -------------------------------- ### PHP ESC/POS: Set Underline Mode Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the underline style for printed text, allowing no underline, single, or double underline. ```APIDOC setUnderline(int $underline) $underline: Either true/false, or one of Printer::UNDERLINE_NONE, Printer::UNDERLINE_SINGLE or Printer::UNDERLINE_DOUBLE. Defaults to Printer::UNDERLINE_SINGLE. ``` -------------------------------- ### PHP Printer Class: Print Barcode Source: https://github.com/mike42/escpos-php/blob/development/README.md Prints a barcode on the printer using the specified content and barcode standard. Supports various standards like UPCA, CODE39, and ITF. Note that some standards are numeric-only, and non-numeric input may cause unexpected behavior. ```APIDOC barcode(string $content, int $type) $content: The information to encode. $type: The barcode standard to output. If not specified, Printer::BARCODE_CODE39 will be used. Supported standards: BARCODE_UPCA, BARCODE_UPCE, BARCODE_JAN13, BARCODE_JAN8, BARCODE_CODE39, BARCODE_ITF, BARCODE_CODABAR ``` -------------------------------- ### PHP Printer Class: Print PDF417 Barcode Source: https://github.com/mike42/escpos-php/blob/development/README.md Prints a two-dimensional data code using the PDF417 standard. Allows customization of module width, height, data column count, error correction ratio, and code options (standard or truncated). ```APIDOC pdf417Code(string $content, number $width, number $heightMultiplier, number $dataColumnCount, real $ec, number $options) $content: Text or numbers to store in the code. $width: Width of a module (pixel) in the printed code. Default is 3 dots. $heightMultiplier: Multiplier for height of a module. Default is 3 times the width. $dataColumnCount: 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. $ec: Error correction ratio, from 0.01 to 4.00. Default is 0.10 (10%). $options: Standard code Printer::PDF417_STANDARD with start/end bars, or truncated code Printer::PDF417_TRUNCATED with start bars only. ``` -------------------------------- ### PHP ESC/POS: Set Print Area Width Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the total width of the print area in dots, effectively adding a right margin. Can be reset to default using `initialize()`. ```APIDOC setPrintWidth(int $width) $width: The width of the page print area, in dots. ``` -------------------------------- ### PHP ESC/POS: Toggle Emphasized Mode Source: https://github.com/mike42/escpos-php/blob/development/README.md Enables or disables emphasized printing mode, making text appear bolder. ```APIDOC setEmphasis(boolean $on) $on: true for emphasis, false for no emphasis. ``` -------------------------------- ### PHP ESC/POS: Set Print Area Left Margin Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the left margin for the print area in dots. Can be reset to default using `initialize()`. ```APIDOC setPrintLeftMargin(int $margin) $margin: The left margin to set on to the print area, in dots. ``` -------------------------------- ### PHP ESC/POS: Set Text Size Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the size of printed text as a multiple of the normal size, for both width and height. ```APIDOC setTextSize(int $widthMultiplier, int $heightMultiplier) $widthMultiplier: Multiple of the regular height to use (range 1 - 8). $heightMultiplier: Multiple of the regular height to use (range 1 - 8). ``` -------------------------------- ### PHP ESC/POS: Toggle Double-Strike Mode Source: https://github.com/mike42/escpos-php/blob/development/README.md Enables or disables double-strike printing mode, which prints characters twice for a bolder appearance. ```APIDOC setDoubleStrike(boolean $on) $on: true for double strike, false for no double strike. ``` -------------------------------- ### PHP ESC/POS: Set Barcode Height Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the height of barcodes in dots. If not specified, a default height of 8 dots is used. ```APIDOC setBarcodeHeight(int $height) $height: Height in dots. If not specified, 8 will be used. ``` -------------------------------- ### PHP ESC/POS: Set Barcode Bar Width Source: https://github.com/mike42/escpos-php/blob/development/README.md Sets the width of barcode bars in dots. Values above 6 appear to have no additional effect. ```APIDOC setBarcodeWidth(int $width) $width: Bar width in dots. If not specified, 3 will be used. Values above 6 appear to have no effect. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.