Add A4 carrier print mode (paper=a4) and document it in README + Swagger

- packing_list renders A5 content into top region of an A4 portrait page
  when paper=a4, so A5 paper loaded horizontally in an A4 tray prints upright
- run.generate/print_document/print_api thread the optional paper param through
- README: new Print Service section with A4 carrier usage + curl example
- Swagger: POST /api/print description documents the A4 carrier mode
This commit is contained in:
Misaka_Company
2026-08-05 16:53:47 +08:00
parent bf9199189a
commit ee2fab3847
5 changed files with 119 additions and 16 deletions

14
run.py
View File

@@ -15,6 +15,7 @@ from __future__ import annotations
import argparse
import importlib
import inspect
import json
import sys
from datetime import datetime
@@ -80,8 +81,12 @@ def _default_output(report_name: str, params: dict) -> str:
return f"out/{report_name}.pdf"
def generate(report_name: str, params: dict, output: str) -> Path:
"""生成指定报表的 PDF。"""
def generate(report_name: str, params: dict, output: str, paper: str | None = None) -> Path:
"""生成指定报表的 PDF。
:param paper: 可选纸张承载模式(如 "a4")。透传给模板的 build_report_definition
模板不接收该参数时(如签收单)自动忽略,不影响原有渲染。
"""
from reportbro import Report # 延迟导入CLI 报错时信息更清晰
report_dir = PROJECT_ROOT / "reports" / report_name
@@ -104,7 +109,10 @@ def generate(report_name: str, params: dict, output: str) -> Path:
# 3. 渲染:模板元素按数据动态布局(明细行高度自适应)
layout = importlib.import_module(f"reports.{report_name}._build_template")
report_def = layout.build_report_definition(context)
if "paper" in inspect.signature(layout.build_report_definition).parameters:
report_def = layout.build_report_definition(context, paper=paper)
else:
report_def = layout.build_report_definition(context)
report = Report(
report_definition=report_def,
data=context,