cups+ippserver+cups4j 进行ipp 打印测试
cups 是一个打印标准,ippserver 属于一个测试mock 的ipp 服务(基于软件的),cups4j 是cups 的一个客户端
环境准备
具体配置参考github,实际配置来自ippsample 的测试配置
version: "3"
services:
ippserver:
image: dalongrong/ippserver
hostname: ippserver
volumes:
- ./test:/config
- ./data/print:/print
- ./data/spool:/spool
- ./data/tools:/tools
command: ippserver -C /config -r _print
cups:
image: olbat/cupsd
privileged: true
ports:
- "632:631"
volumes:
- ./cupsd.conf:/etc/cups/cupsd.conf
- /var/run/dbus:/var/run/dbus
cups 配置
- 添加打印机
参考配置
打印机信息
代码集成
- 核心代码
使用cups4j 客户端
package com.dalong;
import org.cups4j.CupsClient;
import org.cups4j.CupsPrinter;
import org.cups4j.PrintJob;
import org.cups4j.PrintRequestResult;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class App {
public static void main(String[] args) throws Exception {
CupsClient cupsClient = new CupsClient("127.0.0.1", 632);
CupsPrinter cupsPrinter = cupsClient.getDefaultPrinter();
Map<String,String> attr = new HashMap<>();
attr.put("document-format","application/pdf");
attr.put("attributes-charset","utf-8");
InputStream inputStream = new FileInputStream("src/main/resources/v4.pdf");
PrintJob printJob = new PrintJob.Builder(inputStream).attributes(attr).build();
PrintRequestResult printRequestResult = cupsPrinter.print(printJob);
System.out.println(printRequestResult.getJobId());
}
}
- 参考效果
说明
当时测试了一台普通打印机,通过usb 进行连接,发现了一些问题(是可以打印,但是中文是乱码的),同时通过cups 提供的ipp 地址 进行打印是没有问题的
实际还得测试,同时对于直接打印,可以支持的是pdf,图片以及文件。。。,但是对于office 是不能直接支持的,但是可以通过ipp 协议暴露的打印机地址然后
通过office 软件进行打印(选择暴露的打印机即可),以上只是一个简单的测试,基于软件部署环境主要是为了方便测试
参考资料
https://github.com/harwey/cups4j
https://github.com/istopwg/ippsample
https://www.cups.org/
https://openprinting.github.io/cups/
https://github.com/apple/cups
https://www.pwg.org/ipp/everywhere.html
https://github.com/rongfengliang/cups_ippsample_ipp_learning
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
2022-04-15 ajax 带token 的文件下载处理
2022-04-15 nginx 跨域问题解决
2021-04-15 cube.js dremio driver 类型转换bug修改
2021-04-15 xfs 磁盘扩容
2021-04-15 cube.js 动态编译问题
2020-04-15 几个不错的开源formbuilder
2019-04-15 nginx ngx_http_image_filter_module 简单试用