forked from kduma-OSS/PHP-LPD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,73 @@ | ||
php-lpd | ||
======= | ||
# PHP-LPD | ||
|
||
PHP LPD (virtual printer in PHP) | ||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
|
||
* Run `example\server.php` (CLI should be better), the server listens on 127.0.0.1:515 (change that if needed). | ||
LPD Server and Client for PHP language. | ||
|
||
You should be good to go, you can either: | ||
## Install | ||
|
||
* Run `example\client.php` (which works with a lovely class by Mick Sear), change the IP:PORT if needed. | ||
Via Composer | ||
|
||
or | ||
```bash | ||
$ composer require kduma/lpd | ||
``` | ||
|
||
* Install a generic LPR text printer and start printing (if you are printing non-latin characters, please configure your printer with the correct font). | ||
## Usage | ||
|
||
Data sent to the printer is echoed, and then written to a `example\dump.txt` text file, you can change that in `example\server.php`. | ||
### Server | ||
``` php | ||
(new KDuma\LPD\Server\Server()) | ||
->setAddress($address) | ||
->setPort($port) | ||
->setMaxConnections($max_connections) | ||
->setHandler(function ($incoming_data, $ctrl) { | ||
echo $incoming_data; // Do something with it! | ||
}) | ||
->run(); | ||
``` | ||
|
||
### Client | ||
|
||
#### Text print job | ||
|
||
For printing clear text use `TextJob` class: | ||
``` php | ||
$job = new KDuma\LPD\Client\Jobs\TextJob("This is content!"); | ||
$job->appdendContent("\n"); | ||
$job->appdendContent("And this is second line."); | ||
``` | ||
|
||
#### File print job | ||
|
||
For printing files, text or binary, use `FileJob` class: | ||
``` php | ||
$job = new KDuma\LPD\Client\Jobs\FileJob("my_raw_file.txt"); | ||
``` | ||
|
||
#### Print Service | ||
|
||
For printing files, text or binary, use `FileJob` class: | ||
``` php | ||
$configuration = new KDuma\LPD\Client\Configuration($address, $queue_name, $port, $timeout); | ||
|
||
$print_service = new KDuma\LPD\Client\PrintService($configuration); | ||
|
||
$print_service->sendJob($job); | ||
``` | ||
|
||
# Original Attribution | ||
|
||
This package is based on classes created by [Ivan Bozhanov](https://github.com/vakata) | ||
([server](https://github.com/vakata/php-lpd/blob/master/class.lpd.php), 2013) | ||
and Mick Sear | ||
([client](https://github.com/vakata/php-lpd/blob/master/example/class.lpr.php), 2005). | ||
|
||
|
||
|
||
|
||
[ico-version]: https://img.shields.io/packagist/v/kduma/lpd.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/kduma/lpd.svg?style=flat-square | ||
|
||
[link-packagist]: https://packagist.org/packages/kduma/lpd | ||
[link-downloads]: https://packagist.org/packages/kduma/lpd |