Files
37duAutomation/libs/printkit/README.md
T
puddy 3f1951fba1 feat(sdk): 新增 erpsdk 0.1.5 与 printkit 0.1.0
- erpsdk:金蝶云星空(K3Cloud)WebAPI 通用 SDK——账套/组织/AppSecret 登录、
  会话复用、单据查询与读写(Save/Submit/Audit/删除/下推/分配/工作流审批)、
  分组维护、即时库存、报表取数(分页),内置新旧两套 ERP 站点
- printkit:网络打印机直连(IPP over TLS,无驱动无弹窗)——内置 EPSON
  L6570/L565,PDF/图片格式化、Excel·WPS 表格按列过滤排版分页、
  Validate-Job 干跑校验、设备能力预检与参数降级
- 均按 SDK 形态供给:sdk.json / api.json / pyproject.toml / _selftest.py
2026-11-16 11:27:33 +08:00

88 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# printkit · 网络打印 SDK
插件里的打印能力统一走这里:**IPP over TLS 直连打印机,不装驱动、不弹对话框、不走 Windows 打印队列**。
## 内置打印机
| id | 型号 | 部门(备注) | 地址 | 说明 |
|---|---|---|---|---|
| `l6570` | EPSON L6570 Series | **人力资源部** | 172.30.40.254 | 彩色 · **支持双面** · 13 ppm |
| `l565` | EPSON L565 Series | **网络信息部** | 172.30.35.254 | 彩色 · **仅单面** · 9 ppm(默认) |
选机器支持 id / 部门名 / 型号名 / 裸地址:
```python
Printer("l565") # 按 id
Printer("网络信息部") # 按部门
Printer("人力资源部") # -> l6570
Printer("172.30.40.254") # 按地址直连
Printer() # 默认(l565)
```
现场换地址不用改代码:`printkit.configure(path="printers.json")`,或设环境变量
`PRINTKIT_PRINTERS` 指向清单文件:
```json
{"printers": [{"id": "l565", "ip": "172.30.35.254", "note": "网络信息部"}], "default": "l565"}
```
## 快速上手
```python
from printkit import Printer
p = Printer("l565") # 也可 Printer("172.30.40.254") / Printer() 用默认
p.print("单据.pdf") # PDF / PNG / JPG,多页自动逐页提交
p.print("单据.pdf", dry_run=True) # 只校验,不出纸
p.print("单据.pdf", sides="two-sided-long-edge") # L565 上会自动降级并提示
```
Excel / WPS 表格按列过滤后打印(自动分页、每页重复表头、可选合计行):
```python
p.print_sheet("台账.xlsx", sheet="单子传递打印",
filter_col="FRECTUNIT#Name", # 有值才打;0 / #REF! / 空 全部丢弃
total=True) # 末尾加合计行
```
先看排版再决定是否出纸:
```python
pdf = printkit.sheet.build_pdf("台账.xlsx", sheet="单子传递打印",
col="FRECTUNIT#Name", total=True)
open("预览.pdf", "wb").write(pdf)
```
## 设备信息
```python
p.state() # {'state': 'idle', 'queued': 0, 'model': 'EPSON L565 Series', ...}
p.caps() # 全部 IPP 能力属性
p.supports("sides-supported", "two-sided-long-edge")
```
## 几条实测结论(别凭印象改)
1. **必须 TLS**。明文 `POST` 到 631 会被回 `426 Upgrade Required`,`secure=False` 只在排查时用。
2. **不支持 PDF**。`document-format-supported` 里只有
`application/octet-stream / image/pwg-raster / image/urf / image/jpeg`
(`pdf-versions-supported: none`),所以 SDK 统一把 PDF 栅格化成 JPEG 再提交。
3. **不支持的参数不报错**。给 L565 传 `sides=two-sided-long-edge`,即使带
`ipp-attribute-fidelity=true`,设备也只回 `successful-ok` 然后静默按单面打。
所以 SDK 在客户端侧做能力预检并降级(`Printer._adjust`),并打日志。
4. **一张连续表跨页**,不是每人一单:行不跨页拆断,表头每页重复,续页页脚带「(续)」。
## 依赖
`pymupdf`(PDF 渲染)、`openpyxl`(读 xlsx)、`pillow`(图片)。
三者都已预装在执行机 python-env 里,SDK 不做运行时 pip 安装。
## 自测
```powershell
cd libs\printkit
..\..\.venv\Scripts\python.exe -m printkit._selftest -v
```
7 个用例全部离线(不联网、不出纸)。