|
| 1 | +<h1 align="center">PhpAidc LabelPrinter</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://raw.githubusercontent.com/php-aidc/label-printer/master/LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-428F7E" alt="License MIT"></a> |
| 5 | +</p> |
| 6 | + |
| 7 | +PhpAidc LabelPrinter is a library that help you create and print labels on printers that support |
| 8 | +Direct Protocol, Fingerprint, TSPL/TSPL2 languages (Honeywell, Intermec, TSC) via TCP/IP. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +- [Requirements](#requirements) |
| 13 | +- [Installation](#installation) |
| 14 | +- [Basic usage](#basic-usage) |
| 15 | + |
| 16 | +## Requirements |
| 17 | +- PHP 7.1+ |
| 18 | +- ext-mbstring |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +LabelPrinter is installed via [Composer](https://getcomposer.org/): |
| 23 | +```bash |
| 24 | +composer require php-aidc/label-printer |
| 25 | +``` |
| 26 | + |
| 27 | +You can of course also manually edit your composer.json file |
| 28 | +```json |
| 29 | +{ |
| 30 | + "require": { |
| 31 | + "php-aidc/label-printer": "v0.1" |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +## Basic usage |
| 37 | + |
| 38 | +> Some TSPL2-like printers, such as Atol BP41/Rongta RP410, do not support all TSPL2 features. |
| 39 | +
|
| 40 | +##### Read data from printer |
| 41 | + |
| 42 | +```php |
| 43 | +use PhpAidc\LabelPrinter\Printer; |
| 44 | +use PhpAidc\LabelPrinter\Connector\NetworkConnector; |
| 45 | + |
| 46 | +$printer = new Printer(new NetworkConnector('192.168.x.x')); |
| 47 | + |
| 48 | +\var_dump($printer->ask('? VERSION$(0)')); |
| 49 | +// "Direct Protocol 10.15.017559 \r\n" |
| 50 | +``` |
| 51 | + |
| 52 | +##### Create and print label |
| 53 | +```php |
| 54 | +use PhpAidc\LabelPrinter\Enum\Unit; |
| 55 | +use PhpAidc\LabelPrinter\Enum\Anchor; |
| 56 | +use PhpAidc\LabelPrinter\Enum\Charset; |
| 57 | +use PhpAidc\LabelPrinter\Printer; |
| 58 | +use PhpAidc\LabelPrinter\Label\Label; |
| 59 | +use PhpAidc\LabelPrinter\Label\Element; |
| 60 | +use PhpAidc\LabelPrinter\Connector\NetworkConnector; |
| 61 | + |
| 62 | +$printer = new Printer(new NetworkConnector('192.168.x.x')); |
| 63 | + |
| 64 | +$label = Label::create(Unit::MM(), 43, 25) |
| 65 | + ->charset(Charset::UTF8()) |
| 66 | + ->add(Element::textBlock(168, 95, 'Hello!', 'Univers', 8)->box(338, 100, 0)->anchor(Anchor::CENTER())) |
| 67 | + ->add(Element::barcode(10, 10, '123456', 'CODE93')->height(60)); |
| 68 | + |
| 69 | +$printer->print($label); |
| 70 | +``` |
| 71 | + |
| 72 | +##### Add elements for a specific language |
| 73 | +```php |
| 74 | +use PhpAidc\LabelPrinter\Label\Label; |
| 75 | +use PhpAidc\LabelPrinter\Label\Element; |
| 76 | +use PhpAidc\LabelPrinter\Language\Tspl; |
| 77 | +use PhpAidc\LabelPrinter\Language\Fingerprint; |
| 78 | + |
| 79 | +$label = Label::create() |
| 80 | + ->when(Fingerprint::class, static function (Label $label) { |
| 81 | + $label->add(Element::textLine(168, 95, 'Hello!', 'Univers', 8)); |
| 82 | + }) |
| 83 | + ->when(Tspl::class, static function (Label $label) { |
| 84 | + $label->add(Element::textLine(10, 10, 'Hello!', 'ROMAN.TTF', 8)); |
| 85 | + }); |
| 86 | +``` |
| 87 | + |
| 88 | +##### Print images |
| 89 | +```php |
| 90 | +use PhpAidc\LabelPrinter\Label\Label; |
| 91 | +use PhpAidc\LabelPrinter\Label\Element; |
| 92 | +use PhpAidc\LabelPrinter\Language\Tspl; |
| 93 | +use PhpAidc\LabelPrinter\Language\Fingerprint; |
| 94 | + |
| 95 | +$image = new \Imagick('gift.svg'); |
| 96 | +$image->scaleImage(100, 100); |
| 97 | + |
| 98 | +$label = Label::create() |
| 99 | + ->when(Fingerprint::class, static function (Label $label) { |
| 100 | + // from printer's memory — png, bmp, pcx |
| 101 | + $label->add(Element::intImage(10, 10, 'GLOBE.1')); |
| 102 | + // from filesystem |
| 103 | + $label->add(Element::extImage(10, 10, \realpath('alien.png'))); |
| 104 | + }) |
| 105 | + ->when(Tspl::class, static function (Label $label) { |
| 106 | + // from printer's memory — bmp, pcx |
| 107 | + $label->add(Element::intImage(10, 10, 'ALIEN.BMP')); |
| 108 | + }) |
| 109 | + // from filesystem via Imagick — any supported types |
| 110 | + ->add(Element::bitmap(50, 10, $image)); |
| 111 | +``` |
| 112 | + |
| 113 | +##### Print text with emulation |
| 114 | +```php |
| 115 | +use PhpAidc\LabelPrinter\Label\Label; |
| 116 | +use PhpAidc\LabelPrinter\Label\Element; |
| 117 | + |
| 118 | +$label = Label::create() |
| 119 | + ->add(Element::textLine(10, 10, 'Hello!', '/path/to/font/roboto.ttf', 20)->emulate()) |
| 120 | + ->add(Element::textBlock(100, 10, 'Hello again!', '/path/to/font/roboto.ttf', 20)->box(300, 20)->emulate()); |
| 121 | +``` |
| 122 | +Text will be drawn with Imagick and printed as bitmap. |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +The PhpAidc LabelPrinter is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). |
| 127 | + |
| 128 | +> Some ideas taken from [mike42/escpos-php](https://github.com/mike42/escpos-php). |
0 commit comments