Mike42\Escpos\Printer::setPrintBuffer PHP Метод

setPrintBuffer() публичный Метод

Attach a different print buffer to the printer. Buffers are responsible for handling text output to the printer.
public setPrintBuffer ( Mike42\Escpos\PrintBuffers\PrintBuffer $buffer )
$buffer Mike42\Escpos\PrintBuffers\PrintBuffer The buffer to use.
    public function setPrintBuffer(PrintBuffer $buffer)
    {
        if ($buffer === $this->buffer) {
            return;
        }
        if ($buffer->getPrinter() != null) {
            throw new InvalidArgumentException("This buffer is already attached to a printer.");
        }
        if ($this->buffer !== null) {
            $this->buffer->setPrinter(null);
        }
        $this->buffer = $buffer;
        $this->buffer->setPrinter($this);
    }

Usage Example

Пример #1
1
<?php

require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfiles\StarCapabilityProfile;
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
/* This example shows the printing of Latvian text on the Star TUP 592 printer */
$profile = StarCapabilityProfile::getInstance();
/* Option 1: Native character encoding */
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector, $profile);
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
$printer->cut();
$printer->close();
/* Option 2: Image-based output (formatting not available using this output) */
$buffer = new ImagePrintBuffer();
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector, $profile);
$printer->setPrintBuffer($buffer);
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
$printer->cut();
$printer->close();
All Usage Examples Of Mike42\Escpos\Printer::setPrintBuffer