Professional PDF document generator. Use when user needs to create reports, invoices, certificates, portfolios, or any publication-ready PDF. Supports images, tables, charts, TOC, headers/footers, and cross-platform fonts. Generates print-quality PDFs. PDF文档生成、专业报告、发票制作。
专业PDF文档生成器,可生成具有完美排版和布局的出版级PDF文档。
请提供以下信息:
文档类型:(报告/发票/证书/简历/其他)
纸张大小:(A4/Letter/A3/自定义)
方向:(纵向/横向)
页边距:(默认/自定义)
字体要求:(默认/指定字体)
语言:(中文/英文)
特殊要求:(水印/页眉页脚/目录等)
bash
python
python3 << PYEOF
import os
from fpdf import FPDF
from datetime import datetime
class PDFGenerator:
def init(self, config):
self.config = config
self.html_content = []
self.css_content = []
self.font_config = FontConfiguration()
def addpagesetup(self, size=A4, orientation=portrait, margins=None):
设置页面尺寸
if margins is None:
margins = {top: 2cm, right: 2cm, bottom: 2cm, left: 2cm}
page_size = {
A4: 210mm 297mm,
Letter: 216mm 279mm,
A3: 297mm 420mm
}.get(size, size)
self.css_content.append(f
@page {{
size: {page_size} {orientation};
margin: {margins[top]} {margins[right]} {margins[bottom]} {margins[left]};
@top-center {{
content: {self.config.get(header_text, )};
font-size: 9pt;
color: #666;
}}
@bottom-center {{
content: Page counter(page) of counter(pages);
font-size: 9pt;
color: #666;
}}
@bottom-right {{
content: {self.config.get(footer_text, )};
font-size: 9pt;
color: #666;
}}
}}
)
def addbasestyles(self, fontfamily=Noto Serif SC, fontsize=12pt):
添加基础CSS样式
self.css_content.append(f
body {{
font-family: {font_family}, Noto Serif, serif;
font-size: {font_size};
line-height: 1.8;
color: #333;
}}
h1 {{
font-family: {font_family.replace(Serif, Sans)}, Noto Sans, sans-serif;
font-size: 24pt;
color: #1a365d;
border-bottom: 3px solid #3182ce;
padding-bottom: 0.5em;
margin-top: 1.5em;
page-break-after: avoid;
}}
h2 {{
font-family: {font_family.replace(Serif, Sans)}, Noto Sans, sans-serif;
font-size: 18pt;
color: #2c5282;
border-left: 4px solid #3182ce;
padding-left: 1em;
margin-top: 1.2em;
page-break-after: avoid;
}}
h3 {{
font-family: {font_family.replace(Serif, Sans)}, Noto Sans, sans-serif;
font-size: 14pt;
color: #3182ce;
margin-top: 1em;
page-break-after: avoid;
}}
p {{
text-align: justify;
text-indent: 2em;
margin: 0.5em 0;
}}
table {{
width: 100%;
border-collapse: collapse;
margin: 1em 0;
font-size: 10pt;
page-break-inside: avoid;
}}
th {{
background-color: #3182ce;
color: white;
padding: 0.8em;
text-align: left;
font-weight: 600;
}}
td {{
border: 1px solid #e2e8f0;
padding: 0.6em 0.8em;
}}
tr:nth-child(even) {{
background-color: #f7fafc;
}}
.cover {{
text-align: center;
padding-top: 30%;
page-break-after: always;
}}
.cover h1 {{
border: none;
font-size: 28pt;
}}
.cover .subtitle {{
font-size: 14pt;
color: #4a5568;
margin-top: 1em;
}}
.cover .author {{
font-size: 12pt;
margin-top: 2em;
}}
.cover .date {{
font-size: 12pt;
color: #718096;
margin-top: 1em;
}}
.toc {{
page-break-after: always;
}}
.toc a {{
color: #3182ce;
text-decoration: none;
}}
.figure {{
text-align: center;
margin: 1em 0;
page-break-inside: avoid;
}}
.figure img {{
max-width: 100%;
height: auto;
}}
.figure-caption {{
font-size: 10pt;
color: #718096;
margin-top: 0.5em;
}}
.code {{
background-color: #2d3748;
color: #e2e8f0;
padding: 1em;
border-radius: 5px;
font-family: Fira Code, Consolas, monospace;
font-size: 9pt;
white-space: pre-wrap;
page-break-inside: avoid;
}}
.highlight {{
background-color: #ebf8ff;
border: 1px solid #90cdf4;
border-radius: 5px;
padding: 1em;
margin: 1em 0;
}}
.warning {{
background-color: #fffaf0;
border: 1px solid #f6ad55;
border-radius: 5px;
padding: 1em;
margin: 1em 0;
}}
blockquote {{
border-left: 4px solid #718096;
background-color: #f7fafc;
padding: 1em;
margin: 1em 0;
font-style: italic;
}}
ul, ol {{
margin: 0.5em 0;
padding-left: 2em;
}}
li {{
margin-bottom: 0.3em;
}}
strong {{
color: #1a365d;
}}
.page-break {{
page-break-before: always;
}}
)
def add_cover(self, title, subtitle=, author=, date=None):
添加封面页
if date is None:
date = datetime.now().strftime(%Y年%m月%d日)
self.html_content.append(f
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 pdf-studio-1776052803 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 pdf-studio-1776052803 技能
skillhub install pdf-studio-1776052803
文件大小: 7.27 KB | 发布时间: 2026-4-14 09:47