-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_lessons_pdf.py
More file actions
85 lines (71 loc) · 2.51 KB
/
generate_lessons_pdf.py
File metadata and controls
85 lines (71 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from pathlib import Path
from reportlab.lib.colors import HexColor
from reportlab.lib.pagesizes import LETTER
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer
from lesson_notes import LESSONS
def build_pdf(output_path: Path) -> None:
output_path.parent.mkdir(parents=True, exist_ok=True)
styles = getSampleStyleSheet()
title_style = styles["Title"]
title_style.textColor = HexColor("#0F172A")
intro_style = ParagraphStyle(
"Intro",
parent=styles["BodyText"],
fontSize=11,
leading=16,
textColor=HexColor("#334155"),
spaceAfter=16,
)
lesson_title_style = ParagraphStyle(
"LessonTitle",
parent=styles["Heading2"],
fontSize=14,
leading=18,
textColor=HexColor("#0F172A"),
spaceAfter=6,
)
body_style = ParagraphStyle(
"LessonBody",
parent=styles["BodyText"],
fontSize=11,
leading=16,
textColor=HexColor("#1E293B"),
spaceAfter=12,
)
story = [
Paragraph("AI Agent Course Notes", title_style),
Spacer(1, 0.15 * inch),
Paragraph(
"This running summary captures each completed lesson in the toy AI agent project. "
"Each section records the practical change made in the repository and why it matters "
"for the agent we are building step by step.",
intro_style,
),
]
for index, lesson in enumerate(LESSONS, start=1):
story.append(Paragraph(f"{index}. {lesson['title']}", lesson_title_style))
story.append(Paragraph(lesson["summary"], body_style))
def draw_page_number(canvas_obj, doc_obj):
canvas_obj.saveState()
canvas_obj.setFillColor(HexColor("#64748B"))
canvas_obj.setFont("Helvetica", 9)
footer_text = f"Page {doc_obj.page}"
canvas_obj.drawCentredString(LETTER[0] / 2.0, 0.45 * inch, footer_text)
canvas_obj.restoreState()
doc = SimpleDocTemplate(
str(output_path),
pagesize=LETTER,
leftMargin=0.8 * inch,
rightMargin=0.8 * inch,
topMargin=0.8 * inch,
bottomMargin=0.8 * inch,
title="AI Agent Course Notes",
author="Codex",
)
doc.build(story, onFirstPage=draw_page_number, onLaterPages=draw_page_number)
def main() -> None:
build_pdf(Path("output/pdf/ai-agent-lessons.pdf"))
if __name__ == "__main__":
main()