maddin-68 / cups-ipp
CUPS Implementation of IPP - PHP Client API
Requires
- php: >=7.4
- guzzlehttp/psr7: ^2.4
- php-http/client-common: ^2.6
- php-http/message: ^1.13
- php-http/socket-client: ^2.1
- symfony/yaml: ^6.0
Requires (Dev)
- atoum/atoum: ^4.1
- symfony/error-handler: ^6.0
Suggests
- wapmorgan/file-type-detector: Detects file type by filename or content and generates correct mimetype.
This package is auto-updated.
Last update: 2024-10-24 21:15:19 UTC
README
CUPS Implementation of IPP - PHP Client API
CUPS (Common Unix Printing System) is a modular printing system for Unix-like computer operating systems which allows a computer to act as a print server. A computer running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer.
Install via Composer
You can install the component using Composer.
composer require maddin-68/cups-ipp
Then, require the vendor/autoload.php
file to enable the autoloading mechanism provided by Composer.
Otherwise, your application won't be able to find the classes of this component.
Requirements
This library use unix sock connection: unix:///var/run/cups/cups.sock
First of all, check if you have correct access to this file: /var/run/cups/cups.sock
Implementation
List printers
<?php include 'vendor/autoload.php'; use Maddin\Cups\Builder\Builder; use Maddin\Cups\Manager\PrinterManager; use Maddin\Cups\Transport\Client; use Maddin\Cups\Transport\ResponseParser; $client = new Client(); $builder = new Builder(); $responseParser = new ResponseParser(); $printerManager = new PrinterManager($builder, $client, $responseParser); $printers = $printerManager->getList(); foreach ($printers as $printer) { echo $printer->getName().' ('.$printer->getUri().')'.PHP_EOL; }
List all printer's jobs
<?php include 'vendor/autoload.php'; use Maddin\Cups\Builder\Builder; use Maddin\Cups\Manager\JobManager; use Maddin\Cups\Manager\PrinterManager; use Maddin\Cups\Transport\Client; use Maddin\Cups\Transport\ResponseParser; $client = new Client(); $builder = new Builder(); $responseParser = new ResponseParser(); $printerManager = new PrinterManager($builder, $client, $responseParser); $printer = $printerManager->findByUri('ipp://localhost:631/printers/HP-Photosmart-C4380-series'); $jobManager = new JobManager($builder, $client, $responseParser); $jobs = $jobManager->getList($printer, false, 0, 'completed'); foreach ($jobs as $job) { echo '#'.$job->getId().' '.$job->getName().' - '.$job->getState().PHP_EOL; }
Create and send a new job
<?php include 'vendor/autoload.php'; use Maddin\Cups\Builder\Builder; use Maddin\Cups\Manager\JobManager; use Maddin\Cups\Manager\PrinterManager; use Maddin\Cups\Model\Job; use Maddin\Cups\Transport\Client; use Maddin\Cups\Transport\ResponseParser; $client = new Client(); $builder = new Builder(); $responseParser = new ResponseParser(); $printerManager = new PrinterManager($builder, $client, $responseParser); $printer = $printerManager->findByUri('ipp://localhost:631/printers/HP-Photosmart-C4380-series'); $jobManager = new JobManager($builder, $client, $responseParser); $job = new Job(); $job->setName('job create file'); $job->setUsername('demo'); $job->setCopies(1); $job->setPageRanges('1'); $job->addFile('./helloworld.pdf'); $job->addAttribute('media', 'A4'); $job->addAttribute('fit-to-page', true); $result = $jobManager->send($printer, $job);