Generate professional PDF reports with a strong design sense, supporting charts, tables, and multi-page layouts, in a Nordic minimalist style.
Use Cases
- The user says "help me make a beautiful report" or "generate a PDF report from this data"
- The user needs aesthetically pleasing analysis reports, research reports, or project reports
- The user thinks ordinary PDFs are too plain and wants a sense of design
Dependency Installation
Automatically installed on first use:
pip install fpdf2 matplotlib
Execution Method
Use a Python script to generate PDFs with fpdf2 and charts with matplotlib.
Design Style: Nordic Minimalist
- Color Scheme: Mainly dark blue
#2C3E50+ white, with amber yellow#F39C12as the accent color - Fonts: Serif headings + sans-serif body text (system fonts for Chinese)
- Whitespace: Plenty of whitespace, do not cram it full
- Layout: Mainly left-aligned, headings centered
Report Structure Template
from fpdf import FPDF
class ElegantReport(FPDF):
"""Nordic-style PDF report generator."""
def header(self):
self.set_font('Helvetica', 'B', 10)
self.set_text_color(44, 62, 80)
self.cell(0, 10, self.title, align='R')
self.ln(15)
def footer(self):
self.set_y(-15)
self.set_font('Helvetica', '', 8)
self.set_text_color(149, 165, 166)
self.cell(0, 10, f'Page {self.page_no()}/{{nb}}', align='C')
def chapter_title(self, title: str):
self.set_font('Helvetica', 'B', 18)
self.set_text_color(44, 62, 80)
self.cell(0, 15, title)
self.ln(20)
def body_text(self, text: str):
self.set_font('Helvetica', '', 11)
self.set_text_color(52, 73, 94)
self.multi_cell(0, 7, text)
self.ln(5)
Supported Content Elements
- Cover Page: Title, subtitle, date, author
- Table of Contents: Automatically generated chapter table of contents
- Body: Heading levels, paragraphs, lists
- Tables: Data tables with alternating row background colors
- Charts: Statistical charts generated by matplotlib
- Header and Footer: Title + page number
Chart Generation
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('Agg')
def create_chart(data: dict, output_path: str):
"""Generate chart image for embedding in PDF."""
fig, ax = plt.subplots(figsize=(8, 4))
# Nordic color palette
colors = ['#2C3E50', '#E74C3C', '#F39C12', '#27AE60', '#3498DB']
ax.bar(data.keys(), data.values(), color=colors[:len(data)])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.tight_layout()
plt.savefig(output_path, dpi=150, bbox_inches='tight')
plt.close()
Output Specifications
- Default A4 portrait, with ample margins
- Chinese content automatically uses system Chinese fonts
- Chart clarity no lower than 150 DPI
- After generation is complete, inform the user of the file path
- For complex reports, confirm the outline structure first, then generate