-
Notifications
You must be signed in to change notification settings - Fork 871
/
Copy pathcharacter-encodings-with-images.php
63 lines (58 loc) · 2.49 KB
/
character-encodings-with-images.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/* Change to the correct path if you copy this example! */
require __DIR__ . '/../vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\PrintBuffers\EscposPrintBuffer;
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
use Mike42\Escpos\CapabilityProfile;
/**
* This example builds on character-encodings.php, also providing an image-based rendering.
* This is quite slow, since a) the buffers are changed dozens of
* times in the example, and b) It involves sending very wide images, which printers don't like!
*
* There are currently no test cases around the image printing, since it is an experimental feature.
*
* It does, however, illustrate the way that more encodings are available when image output is used.
*/
include(dirname(__FILE__) . '/resources/character-encoding-test-strings.inc');
try {
// Enter connector and capability profile
$connector = new FilePrintConnector("php://stdout");
$profile = CapabilityProfile::load('default');
$buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
/* Print a series of receipts containing i18n example strings */
$printer = new Printer($connector, $profile);
$printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
$printer -> text("Implemented languages\n");
$printer -> selectPrintMode();
foreach ($inputsOk as $label => $str) {
$printer -> setEmphasis(true);
$printer -> text($label . ":\n");
$printer -> setEmphasis(false);
foreach ($buffers as $buffer) {
$printer -> setPrintBuffer($buffer);
$printer -> text($str);
}
$printer -> setPrintBuffer($buffers[0]);
}
$printer -> feed();
$printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
$printer -> text("Works in progress\n");
$printer -> selectPrintMode();
foreach ($inputsNotOk as $label => $str) {
$printer -> setEmphasis(true);
$printer -> text($label . ":\n");
$printer -> setEmphasis(false);
foreach ($buffers as $buffer) {
$printer -> setPrintBuffer($buffer);
$printer -> text($str);
}
$printer -> setPrintBuffer($buffers[0]);
}
$printer -> cut();
/* Close printer */
$printer -> close();
} catch (Exception $e) {
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}