<?php require __DIR__ . '/../../autoload.php'; use Mike42\Escpos\Printer; use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile; $connector = new FilePrintConnector("php://stdout"); $profile = DefaultCapabilityProfile::getInstance(); $printer = new Printer($connector, $profile); $printer->text("Μιχάλης Νίκος\n"); $printer->cut(); $printer->close();
/** * Construct a new print object * * @param PrintConnector $connector The PrintConnector to send data to. If not set, output is sent to standard output. * @param AbstractCapabilityProfile $profile Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers. * @throws InvalidArgumentException */ function __construct(PrintConnector $connector = null, AbstractCapabilityProfile $profile = null) { if (is_null($connector)) { if (php_sapi_name() == 'cli') { $connector = new FilePrintConnector("php://stdout"); } else { throw new InvalidArgumentException("Argument passed to Escpos::__construct() must implement interface PrintConnector, null given."); } } /* Set connector */ $this->connector = $connector; /* Set capability profile */ if ($profile === null) { $profile = DefaultCapabilityProfile::getInstance(); } $this->profile = $profile; /* Set buffer */ $buffer = new EscposPrintBuffer(); $this->buffer = null; $this->setPrintBuffer($buffer); $this->initialize(); }
/** * Construct a new print object * * @param PrintConnector $connector The PrintConnector to send data to. If not set, output is sent to standard output. * @param AbstractCapabilityProfile $profile Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers. * @throws InvalidArgumentException */ function __construct(PrintConnector $connector, AbstractCapabilityProfile $profile = null) { /* Set connector */ $this->connector = $connector; /* Set capability profile */ if ($profile === null) { $profile = DefaultCapabilityProfile::getInstance(); } $this->profile = $profile; /* Set buffer */ $buffer = new EscposPrintBuffer(); $this->buffer = null; $this->setPrintBuffer($buffer); $this->initialize(); }