定制 josh-gaby/cups-ipp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josh-gaby/cups-ipp

Composer 安装命令:

composer require josh-gaby/cups-ipp

包简介

CUPS Implementation of IPP - PHP Client API (PHP >= 7.2.5)

README 文档

README

CUPS Implementation of IPP - PHP Client API

(another fork of the awesome smalot/cups-ipp, updated to use GuzzleHttp\Client, supports PHP >= 7.2.5)

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.

Build Status Current Version Total Downloads Latest Unstable Version License

Install via Composer

You can install the component using Composer.

composer require josh-gaby/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 Smalot\Cups\Builder\Builder;
use Smalot\Cups\Manager\PrinterManager;
use Smalot\Cups\Transport\Client;
use Smalot\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 Smalot\Cups\Builder\Builder;
use Smalot\Cups\Manager\JobManager;
use Smalot\Cups\Manager\PrinterManager;
use Smalot\Cups\Transport\Client;
use Smalot\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 Smalot\Cups\Builder\Builder;
use Smalot\Cups\Manager\JobManager;
use Smalot\Cups\Manager\PrinterManager;
use Smalot\Cups\Model\Job;
use Smalot\Cups\Transport\Client;
use Smalot\Cups\Transport\ResponseParser;

$client = new Client();
$builder = new Builder();
$responseParser = new ResponseParser();

$printerManager = new PrinterManager($builder, $client, $responseParser);
// Find the printer by the Uri
//$printer = $printerManager->findByUri('ipp://localhost:631/printers/HP-Photosmart-C4380-series');

// or by the name
$printers = $printerManager->findByName('HP-Photosmart-C4380-series');
if (!empty($printers)) {
    $printer = $printers[0];
    $jobManager = new JobManager($builder, $client, $responseParser);
    
    $job = new Job();
    $job->setName('job create file');
    $job->setUsername('demo');
    $job->setCopies(1);
    $job->setPageRanges('1'); // This can be left out, it will print all pages by default
    $job->addFile('./helloworld.pdf');
    $job->addAttribute('media', 'A4');
    $job->addAttribute('fit-to-page', true);
    $result = $jobManager->send($printer, $job);
}

Remote CUPS server

You can easily connect to a remote CUPS server by supplying the connection details when constructing the Client.

<?php

include 'vendor/autoload.php';

use Smalot\Cups\Builder\Builder;
use Smalot\Cups\Manager\JobManager;
use Smalot\Cups\Manager\PrinterManager;
use Smalot\Cups\Transport\Client;
use Smalot\Cups\Transport\ResponseParser;

$client = new Client('username', 'password', ['remote_socket' => 'http://server-ip:631']);
$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;
}

josh-gaby/cups-ipp 适用场景与选型建议

josh-gaby/cups-ipp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.44k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「print」 「printing」 「CUPS」 「ipp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 josh-gaby/cups-ipp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 josh-gaby/cups-ipp 我们能提供哪些服务?
定制开发 / 二次开发

基于 josh-gaby/cups-ipp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 56
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-11-26