76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
class EscposPrinter {
|
|
private $tempFile = null;
|
|
private $instance = null;
|
|
private $html = null;
|
|
|
|
public function __construct() {
|
|
$this->init_instance();
|
|
$this->html = "";
|
|
}
|
|
|
|
public function init_instance() {
|
|
$this->tempFile = Cache::tempFile();
|
|
$connector = new Mike42\Escpos\PrintConnectors\FilePrintConnector($this->tempFile);
|
|
// $connector = new Mike42\Escpos\PrintConnectors\NetworkPrintConnector("127.0.0.1", 9100);
|
|
$this->instance = new Mike42\Escpos\Printer($connector);
|
|
}
|
|
|
|
public function get_blob() {
|
|
if (!is_null($this->tempFile) && file_exists($this->tempFile)) {
|
|
return file_get_contents($this->tempFile);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function to_html() {
|
|
return $this->html;
|
|
}
|
|
|
|
|
|
// <editor-fold desc="FUNZIONI Mike42\Escpos" defaultstate="collapsed">
|
|
const MODE_DOUBLE_WIDTH = Mike42\Escpos\Printer::MODE_DOUBLE_WIDTH;
|
|
const MODE_FONT_A = Mike42\Escpos\Printer::MODE_FONT_A;
|
|
const MODE_FONT_B = Mike42\Escpos\Printer::MODE_FONT_B;
|
|
const JUSTIFY_LEFT = Mike42\Escpos\Printer::JUSTIFY_LEFT;
|
|
const JUSTIFY_CENTER = Mike42\Escpos\Printer::JUSTIFY_CENTER;
|
|
const JUSTIFY_RIGHT = Mike42\Escpos\Printer::JUSTIFY_RIGHT;
|
|
|
|
public function feed($lines = 1) {
|
|
$this->instance->feed($lines);
|
|
return $this;
|
|
}
|
|
|
|
public function text($str = "") {
|
|
$this->instance->text($str);
|
|
$this->html .= str_replace(" ", " ", str_replace("\n", "<br/>", $str));
|
|
return $this;
|
|
}
|
|
|
|
public function selectPrintMode($mode = self::MODE_FONT_A) {
|
|
$this->instance->selectPrintMode($mode);
|
|
return $this;
|
|
}
|
|
|
|
public function setEmphasis($on = true) {
|
|
$this->instance->setEmphasis($on);
|
|
return $this;
|
|
}
|
|
|
|
public function setJustification($justification = self::JUSTIFY_LEFT) {
|
|
$this->instance->setJustification($justification);
|
|
return $this;
|
|
}
|
|
|
|
public function cut($mode = Mike42\Escpos\Printer::CUT_FULL, $lines = 3) {
|
|
$this->instance->cut($mode, $lines);
|
|
return $this;
|
|
}
|
|
|
|
public function close() {
|
|
$this->instance->close();
|
|
return $this;
|
|
}
|
|
// </editor-fold>
|
|
} |