简介
基于 ReportLab 与开源 easy-invoice-pdf 库,一键生成企业级 PDF 发票,支持模板定制与批量处理,提升财务工作效率。
原始描述
Free simple invoice generator. Creates clean, professional invoices with your branding. Use when you need to bill a client quickly without complex tracking o...
通过你的 Agent 添加
点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。
或者手动安装
包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。
技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。
中文使用说明 来自收录源
核心用法
Invoice Template Skill 是一款纯文档型技能,专注于指导用户使用 Python 生成专业 PDF 发票。它提供了两种主流技术方案:
-
ReportLab 原生方案:直接使用 Python 的 ReportLab 库进行底层 PDF 绘制,适合需要精细控制页面布局和样式的场景。代码示例涵盖页眉设置、发票详情、买卖双方信息、商品表格及税费计算等完整流程。
-
HTML模板方案:采用 Jinja2 + WeasyPrint 组合,通过 HTML/CSS 定义发票样式再转换为 PDF,更适合前端开发者或需要频繁修改样式的业务场景。
显著优点
- 零依赖风险:纯 Markdown 文档型 Skill,无可执行代码,仅提供代码示例和最佳实践
- 技术路线清晰:同时覆盖底层绘制和模板化两种方案,开发者可按需选择
- 数据结构标准化:提供了完整的发票 JSON Schema,包含发票号、日期、买卖双方、商品明细、税率等核心字段
- 最佳实践完备:明确列出四项关键实践——字段验证、品牌一致性、自动计算 totals、付款条款说明
潜在缺点与局限性
- 非开箱即用:需要用户自行安装依赖(reportlab、weasyprint、jinja2)并编写集成代码
- 缺乏高级功能:未覆盖多币种、多语言、电子签名、二维码支付等现代发票需求
- 模板自定义成本:HTML 方案虽灵活,但需要 CSS 调试经验;ReportLab 方案则需要 Python 绘图知识
- 无批量处理示例:虽然提及"Batch generate monthly invoices",但未提供并发或大数据量处理的代码参考
适合人群
- 中小企业技术团队,需自建开票系统而非采购 SaaS
- 已有 Python 后端,希望扩展发票导出功能的开发者
- 学习 ReportLab 或 PDF 生成的技术人员
常规风险
- 依赖版本兼容性:建议生产环境锁定 reportlab>=3.6.0 和 weasyprint 版本
- 财税合规性:不同国家/地区对发票格式、税率计算、电子发票合法性有差异化要求,代码示例中的 8% 税率和简单计算逻辑需根据实际业务调整
- 数据验证缺失:示例代码未展示输入验证逻辑,直接使用可能因数据格式错误导致 PDF 生成失败
技能正文
name: invoice-template description: Generate professional PDF invoices from templates author: claude-office-skills version: "1.0" tags: ['invoice', 'pdf', 'template', 'billing'] models: [claude-sonnet-4, claude-opus-4] tools: [computer, code_execution, file_operations] library: name: easy-invoice-pdf url: https://github.com/nickmitchko/easy-invoice-pdf stars: 476
Invoice Template Skill
Overview
This skill generates professional PDF invoices from structured data and templates. Create invoices with company branding, itemized lists, tax calculations, and payment details.
How to Use
- Describe what you want to accomplish
- Provide any required input data or files
- I'll execute the appropriate operations
Example prompts:
- "Generate invoices from order data"
- "Create recurring invoices"
- "Batch generate monthly invoices"
- "Customize invoice templates per client"
Domain Knowledge
Invoice Data Structure
invoice_data = {
"invoice_number": "INV-2026-001",
"date": "2026-01-30",
"due_date": "2026-02-28",
"from": {
"name": "Your Company",
"address": "123 Business St",
"email": "billing@company.com"
},
"to": {
"name": "Client Name",
"address": "456 Client Ave",
"email": "client@example.com"
},
"items": [
{"description": "Consulting", "quantity": 10, "rate": 150.00},
{"description": "Development", "quantity": 20, "rate": 100.00}
],
"tax_rate": 0.08,
"notes": "Payment due within 30 days"
}
PDF Generation with ReportLab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
def create_invoice(data: dict, output_path: str):
c = canvas.Canvas(output_path, pagesize=letter)
width, height = letter
# Header
c.setFont("Helvetica-Bold", 24)
c.drawString(1*inch, height - 1*inch, "INVOICE")
# Invoice details
c.setFont("Helvetica", 12)
c.drawString(1*inch, height - 1.5*inch, f"Invoice #: {data['invoice_number']}")
c.drawString(1*inch, height - 1.75*inch, f"Date: {data['date']}")
# From/To
y = height - 2.5*inch
c.drawString(1*inch, y, f"From: {data['from']['name']}")
c.drawString(4*inch, y, f"To: {data['to']['name']}")
# Items table
y = height - 4*inch
c.setFont("Helvetica-Bold", 10)
c.drawString(1*inch, y, "Description")
c.drawString(4*inch, y, "Qty")
c.drawString(5*inch, y, "Rate")
c.drawString(6*inch, y, "Amount")
c.setFont("Helvetica", 10)
subtotal = 0
for item in data['items']:
y -= 0.3*inch
amount = item['quantity'] * item['rate']
subtotal += amount
c.drawString(1*inch, y, item['description'])
c.drawString(4*inch, y, str(item['quantity']))
c.drawString(5*inch, y, f"${item['rate']:.2f}")
c.drawString(6*inch, y, f"${amount:.2f}")
# Totals
tax = subtotal * data['tax_rate']
total = subtotal + tax
y -= 0.5*inch
c.drawString(5*inch, y, f"Subtotal: ${subtotal:.2f}")
y -= 0.25*inch
c.drawString(5*inch, y, f"Tax ({data['tax_rate']*100}%): ${tax:.2f}")
y -= 0.25*inch
c.setFont("Helvetica-Bold", 12)
c.drawString(5*inch, y, f"Total: ${total:.2f}")
c.save()
return output_path
HTML Template Approach
from weasyprint import HTML
from jinja2 import Template
invoice_template = """
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
.header { display: flex; justify-content: space-between; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
.total { font-weight: bold; font-size: 18px; }
</style>
</head>
<body>
<div class="header">
<h1>INVOICE</h1>
<div>
<p>Invoice #: {{ invoice_number }}</p>
<p>Date: {{ date }}</p>
</div>
</div>
<table>
<tr><th>Description</th><th>Qty</th><th>Rate</th><th>Amount</th></tr>
{% for item in items %}
<tr>
<td>{{ item.description }}</td>
<td>{{ item.quantity }}</td>
<td>${{ "%.2f"|format(item.rate) }}</td>
<td>${{ "%.2f"|format(item.quantity * item.rate) }}</td>
</tr>
{% endfor %}
</table>
<p class="total">Total: ${{ "%.2f"|format(total) }}</p>
</body>
</html>
"""
def create_invoice_html(data: dict, output_path: str):
template = Template(invoice_template)
# Calculate total
total = sum(i['quantity'] * i['rate'] for i in data['items'])
total *= (1 + data.get('tax_rate', 0))
data['total'] = total
html = template.render(**data)
HTML(string=html).write_pdf(output_path)
return output_path
Best Practices
- Validate required fields before generation
- Use templates for consistent branding
- Auto-calculate totals (don't trust input)
- Include payment instructions and terms
Installation
# Install required dependencies
pip install python-docx openpyxl python-pptx reportlab jinja2
Resources
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。