关于 certificate-generator
certificate-generator 用于制作课程、活动、成就和奖项证书,并导出为 PDF。它提供预设样式、品牌与签名选项,也支持根据 CSV 批量生成。
主要功能
- 01提供五种预设证书模板
- 02添加徽标、颜色和签名
- 03根据 CSV 数据生成证书
- 04设置收件人和成就等动态字段
- 05分配唯一证书 ID
- 06导出横向或纵向 PDF
适用场景
- 01颁发课程完成证书
- 02制作活动参与证书
- 03批量生成员工培训证书
- 04制作带组织品牌元素的成就奖状
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ dkyazzentwatwa/ chatgpt-skills --skill certificate-generator安装后在 Claude Code 中输入/certificate-generator确认已加载。
附带文件scripts/certificate_gen.pyscripts/requirements.txt
详细介绍
证书生成器
为课程、成就、活动和奖项制作专业证书。支持从 CSV 文件批量生成,并可自定义模板和品牌元素。
快速开始
from scripts.certificate_gen import CertificateGenerator
# Single certificate
cert = CertificateGenerator()
cert.set_title("Certificate of Completion")
cert.set_recipient("John Smith")
cert.set_achievement("Python Programming Course")
cert.set_date("December 14, 2024")
cert.generate().save("certificate.pdf")
# Batch from CSV
CertificateGenerator.batch_generate(
"students.csv",
template="achievement",
title="Certificate of Completion",
achievement="Data Science Bootcamp",
output_dir="./certificates/"
)
功能
- 专业模板:现代、经典、优雅、简约风格
- 自定义品牌元素:徽标、颜色、签名
- 批量生成:从 CSV 创建数百份证书
- 动态字段:姓名、日期、成就、讲师等
- 签名:带头衔的文本或图片签名
- 证书 ID:自动生成唯一标识符
- 导出:PDF 输出,支持横向或纵向
API 参考
初始化
cert = CertificateGenerator()
# With template
cert = CertificateGenerator(template="elegant")
证书内容
# Title
cert.set_title("Certificate of Completion")
cert.set_title("Certificate of Achievement")
# Recipient name
cert.set_recipient("Jane Doe")
# Achievement/course/event
cert.set_achievement("Advanced Python Programming")
cert.set_achievement("for outstanding performance in the 2024 Hackathon")
# Description (optional)
cert.set_description(
"Has successfully completed the 40-hour intensive course "
"covering advanced topics in Python programming."
)
# Date
cert.set_date("December 14, 2024")
cert.set_date_auto() # Use today's date
# Certificate ID (auto-generated if not set)
cert.set_certificate_id("CERT-2024-001")
品牌元素
# Organization name
cert.set_organization("Acme Academy")
# Logo
cert.set_logo("logo.png")
cert.set_logo("logo.png", width=200)
# Colors
cert.set_colors(
primary="#1e3a5f", # Main color (title, borders)
accent="#c9a227", # Accent color (decorations)
text="#333333" # Text color
)
签名
# Text signature
cert.add_signature(
name="Dr. Jane Smith",
title="Program Director"
)
# Multiple signatures
cert.add_signature("John Doe", "CEO")
cert.add_signature("Jane Smith", "Head of Training")
# Image signature
cert.add_signature(
name="Dr. Jane Smith",
title="Program Director",
signature_image="signature.png"
)
模板
# Available templates
cert.set_template("modern") # Clean, contemporary design
cert.set_template("classic") # Traditional, formal design
cert.set_template("elegant") # Decorative borders, serif fonts
cert.set_template("minimal") # Simple, clean design
cert.set_template("academic") # University/school style
# Orientation
cert.set_orientation("landscape") # Default
cert.set_orientation("portrait")
生成与导出
# Generate certificate
cert.generate()
# Save to PDF
cert.save("certificate.pdf")
# Get PDF bytes
pdf_bytes = cert.to_bytes()
批量生成
从 CSV 生成
# CSV with recipient data
CertificateGenerator.batch_generate(
csv_file="students.csv",
template="achievement",
title="Certificate of Completion",
achievement="Python Fundamentals",
organization="Code Academy",
output_dir="./certificates/"
)
CSV 格式
name,date,course,certificate_id
John Smith,2024-12-14,Python 101,CERT-001
Jane Doe,2024-12-14,Python 101,CERT-002
Bob Johnson,2024-12-14,Python 101,CERT-003
以编程方式批量生成
recipients = [
{"name": "John Smith", "course": "Python 101"},
{"name": "Jane Doe", "course": "Data Science"},
{"name": "Bob Johnson", "course": "Machine Learning"}
]
for r in recipients:
cert = CertificateGenerator(template="modern")
cert.set_title("Certificate of Completion")
cert.set_recipient(r["name"])
cert.set_achievement(r["course"])
cert.set_date_auto()
cert.generate()
cert.save(f"certificates/{r['name'].replace(' ', '_')}.pdf")
CLI 用法
# Single certificate
python certificate_gen.py \
--recipient "John Smith" \
--title "Certificate of Completion" \
--achievement "Python Course" \
--output certificate.pdf
# With options
python certificate_gen.py \
--recipient "Jane Doe" \
--title "Certificate of Achievement" \
--achievement "Excellence in Data Science" \
--organization "Data Academy" \
--template elegant \
--logo logo.png \
--output achievement.pdf
# Batch from CSV
python certificate_gen.py \
--batch students.csv \
--title "Certificate of Completion" \
--achievement "Bootcamp Graduate" \
--template modern \
--output-dir ./certificates/
CLI 参数
| 参数 | 说明 | 默认值 |
|---|---|---|
--recipient | 收件人姓名 | 必填 |
--title | 证书标题 | Certificate |
--achievement | 成就文本 | - |
--description | 描述文本 | - |
--organization | 机构名称 | - |
--date | 证书日期 | 今天 |
--template | 模板样式 | modern |
--logo | 徽标图片路径 | - |
--output | 输出 PDF 路径 | certificate.pdf |
--batch | 用于批量生成的 CSV 文件 | - |
--output-dir | 输出目录(批量生成) | ./ |
模板
现代
简洁、时尚的设计,包含:
- 无衬线字体
- 极简装饰
- 醒目的色彩点缀
- 专业风格
经典
传统设计,包含:
- 衬线字体
- 正式版式
- 边框装饰
- 历久弥新的优雅风格
优雅
装饰性设计,包含:
- 华丽边框
- 姓名使用手写体字体
- 金色点缀
- 高级质感
简约
简洁设计,包含:
- 清晰的排版
- 无装饰
- 大量留白
- 现代简约风格
学术
大学风格设计,包含:
- 校徽/盾徽布局
- 正式排版
- 官方风格
- 传统版式
示例
课程结业证书
cert = CertificateGenerator(template="modern")
cert.set_title("Certificate of Completion")
cert.set_recipient("John Smith")
cert.set_achievement("Full Stack Web Development")
cert.set_description(
"Has successfully completed the 12-week intensive program "
"covering HTML, CSS, JavaScript, React, Node.js, and databases."
)
cert.set_organization("Tech Academy")
cert.set_logo("tech_academy_logo.png")
cert.set_date("December 14, 2024")
cert.add_signature("Sarah Johnson", "Program Director")
cert.generate().save("completion_cert.pdf")
成就奖
cert = CertificateGenerator(template="elegant")
cert.set_title("Certificate of Achievement")
cert.set_recipient("Jane Doe")
cert.set_achievement("First Place - Annual Hackathon 2024")
cert.set_organization("Innovation Labs")
cert.set_colors(primary="#1a1a2e", accent="#d4af37")
cert.add_signature("Michael Chen", "CEO")
cert.add_signature("Emily Brown", "CTO")
cert.generate().save("achievement_award.pdf")
工作坊参与证书
cert = CertificateGenerator(template="minimal")
cert.set_title("Certificate of Participation")
cert.set_recipient("Bob Wilson")
cert.set_achievement("Machine Learning Workshop")
cert.set_description("Attended the 2-day intensive workshop on Dec 12-13, 2024")
cert.set_date_auto()
cert.generate().save("workshop_cert.pdf")
员工培训批量生成
# training_completed.csv
# name,department,course
# Alice,Engineering,Safety Training
# Bob,Sales,Product Training
# Carol,HR,Compliance Training
CertificateGenerator.batch_generate(
csv_file="training_completed.csv",
template="classic",
title="Training Completion Certificate",
organization="Acme Corp",
logo="acme_logo.png",
output_dir="./training_certs/",
filename_pattern="{name}_{course}.pdf"
)
依赖项
reportlab>=4.0.0
Pillow>=10.0.0
限制
- 仅支持 PDF 输出(不支持 PNG/图片导出)
- 仅提供预定义模板(不支持自定义 HTML/CSS)
- 每份证书最多支持 3 个签名
- 徽标应为 PNG 或 JPEG 格式
- 仅提供英文模板(不支持从右向左书写的语言)
评论
支持 Markdown