← 返回
未分类 中文

PDF Report

Generate clean A4 PDF reports from structured JSON using Jinja2 and WeasyPrint. Use when the user needs a formatted PDF document — analytical summary, data r...
使用 Jinja2 和 WeasyPrint 从结构化 JSON 生成整洁的 A4 PDF 报告,适用于需要格式化 PDF 文档的场景,如分析摘要、数据报告等。
mohamed-hammane
未分类 clawhub v1.0.1 2 版本 100000 Key: 无需
★ 0
Stars
📥 536
下载
💾 23
安装
2
版本
#latest

概述

PDF Report

Generate a clean A4 PDF from structured JSON data.

Setup

Install system dependencies (WeasyPrint requires these):

# Ubuntu/Debian
sudo apt-get install -y libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev libcairo2

Create a virtual environment and install Python dependencies (one-time):

python3 -m venv ~/.openclaw/workspace/.venv_pdf
~/.openclaw/workspace/.venv_pdf/bin/pip install weasyprint jinja2

Quick start

~/.openclaw/workspace/.venv_pdf/bin/python skills/pdf-report/scripts/render_pdf.py \
  --input exports/report-data.json \
  --output exports/pdfs/report.pdf

Inputs

  • --input path to a JSON file inside the workspace
  • --output path to the PDF output inside the workspace
  • Optional: --template-file custom Jinja2 template path inside the workspace
  • Optional: --html-out write the rendered HTML for debugging

Expected JSON shape

{
  "title": "Monthly Report",
  "subtitle": "Summary by region",
  "generated_at": "2026-03-23 10:00",
  "summary": ["Key point 1", "Key point 2"],
  "sections": [
    {
      "title": "Sales by category",
      "lead": "National overview",
      "items": ["Observation 1", "Observation 2"],
      "table": {
        "headers": ["Category", "Amount", "Share"],
        "rows": [["Electronics", "12 450", "45%"]]
      },
      "charts": [
        {
          "title": "Distribution by category",
          "src": "exports/charts/category.png",
          "caption": "Source: sales database"
        }
      ],
      "note": "Data as of 31/12/2025"
    }
  ],
  "footer": "Company Name — Department"
}

Notes

  • All file paths (CLI arguments and charts[].src in JSON) must stay inside the workspace. Paths outside the workspace are rejected.
  • Missing chart images produce a warning to stderr but do not block PDF generation.
  • Use chart-mpl first when a section needs chart images, then reference those image paths in charts[].src.
  • Output directories are created automatically.
  • Default template: skills/pdf-report/templates/report.html
  • Dedicated venv: ~/.openclaw/workspace/.venv_pdf/ (weasyprint + jinja2)
  • Pages are numbered automatically (bottom-right: "1 / 3").

Custom templates

Use --template-file to provide your own Jinja2 HTML template. Note that relative asset paths inside custom templates (images, CSS) resolve from the workspace root, not the template's directory. Use workspace-root-relative paths for any referenced assets.

版本历史

共 2 个版本

  • v1.0.1 当前
    2026-05-03 05:53 安全 安全
  • v1.0.0
    2026-03-31 01:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Chart MPL

mohamed-hammane
使用matplotlib从CSV数据生成PNG/SVG图表(折线、柱状、水平柱状、饼图、堆叠、散点、面积图),用于用户请求可视化表格数据的场景。
★ 0 📥 547

Excel Export

mohamed-hammane
从结构化JSON生成精美的.xlsx工作簿,支持多工作表、冻结表头、筛选、类型化列、公式、合计以及法国/摩洛哥格式。
★ 0 📥 459

IMAP SMTP Email

mohamed-hammane
使用本地 Node脚本通过 IMAP/SMTP 读取和发送邮件,适用于需要检查收件箱、获取邮件内容、搜索邮件、下载附件等场景。
★ 0 📥 451