Invoice Template

作者 claude-office-skills9c4c7d5cd281MIT499 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫8 個月前更新

Generate professional PDF invoices from templates

AI 產生的概覽

依結構化資料與範本產生專業的 PDF 發票,包含明細項目、稅額與總計。

功能
此技能會依結構化發票資料(例如發票編號、日期、開立方與客戶資訊、明細項目、稅率與備註)產生 PDF 發票。內容記錄了兩種產生方式:ReportLab 畫布腳本,以及以 Jinja2 HTML 範本搭配 WeasyPrint 輸出為 PDF。內容也涵蓋發票資料結構、欄位驗證與自動計算總計的最佳實務,以及相依套件安裝說明。
適用情境
當你需要依訂單或帳務資料建立單張、週期性或批次發票時使用。適合產出帶有品牌資訊、明細項目、稅額與付款條件的 PDF 發票。
執行需求
僅為說明文件,技能未附腳本。所述方式需要 Python 及 reportlab、jinja2、weasyprint(安裝說明另列出 python-docx、openpyxl、python-pptx),中繼資料也引用了具備 create_docx、fill_docx_template 與 docx_to_pdf 工具的 office-mcp 伺服器。

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

  1. Describe what you want to accomplish
  2. Provide any required input data or files
  3. 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

python
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": "[email protected]"    },        "to": {        "name": "Client Name",        "address": "456 Client Ave",        "email": "[email protected]"    },        "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

python
from reportlab.lib.pagesizes import letterfrom reportlab.pdfgen import canvasfrom 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

python
from weasyprint import HTMLfrom 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

  1. Validate required fields before generation
  2. Use templates for consistent branding
  3. Auto-calculate totals (don't trust input)
  4. Include payment instructions and terms

Installation

bash
# Install required dependenciespip install python-docx openpyxl python-pptx reportlab jinja2

Resources

來源與署名

來源:claude-office-skills/skills位於invoice-template提交9c4c7d5

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架