/** * 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(); }
* a built-in capability profile, you need to check its documentation for * supported code pages. * * These are then loaded into a capability profile, which maps code page * numbers to iconv encoding names on your particular printer. This script * will print all configured code pages, so that you can check that the chosen * iconv encoding name matches the actual code page contents. * * If this is correctly set up for your printer, then the driver will try its * best to map UTF-8 text into these code pages for you, allowing you to accept * arbitrary input from a database, without worrying about encoding it for the printer. */ require_once dirname(__FILE__) . "/../Escpos.php"; // Enter connector and capability profile (to match your printer) $connector = new FilePrintConnector("php://stdout"); $profile = DefaultCapabilityProfile::getInstance(); $verbose = false; // Skip tables which iconv wont convert to (ie, only print characters available with UTF-8 input) /* Print a series of receipts containing i18n example strings - Code below shouldn't need changing */ $printer = new Escpos($connector, $profile); $codePages = $profile->getSupportedCodePages(); $first = true; // Print larger table for first code-page. foreach ($codePages as $table => $name) { /* Change printer code page */ $printer->selectCharacterTable(255); $printer->selectCharacterTable($table); /* Select & print a label for it */ $label = $name; if ($name === false) { $label = " (not matched to iconv table)";