PHP code example of blutrixx / nativephp-escpos-printer

1. Go to this page and download the library: Download blutrixx/nativephp-escpos-printer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blutrixx / nativephp-escpos-printer example snippets


use Blutrixx\EscPosPrinter\Facades\EscPosPrinter;

if (! EscPosPrinter::isConnected()) {
    EscPosPrinter::connect();
}

EscPosPrinter::print("Hello, receipt!\n");

EscPosPrinter::processLogoInCommands("[C]<img>{{LOGO:my-brand-logo.png}}</img>\n");
// or, with ESCPOS_PRINTER_DEFAULT_LOGO=my-brand-logo.png set:
EscPosPrinter::processLogoInCommands("[C]<img>{{LOGO}}</img>\n");

use Blutrixx\EscPosPrinter\Facades\EscPosPrinter;

EscPosPrinter::ensureConnected();
EscPosPrinter::print("[C]<b>RECEIPT</b>\n[L]Item 1          $5.00\n");
EscPosPrinter::testPrint();
EscPosPrinter::disconnect();

// routes/api.php
Route::post('/printer/print-receipt', function () {
    return \Blutrixx\EscPosPrinter\Facades\EscPosPrinter::print(
        "[C]<img>{{LOGO}}</img>\n" .
        "[C]<b>Thank you for your purchase</b>\n" .
        "[L]Total: $42.00\n"
    );
});