PHP code example of maddin-68 / cups-ipp

1. Go to this page and download the library: Download maddin-68/cups-ipp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maddin-68 / cups-ipp example snippets




addin\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;
}




addin\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;
}




addin\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);