"""Generate PDF from MAC API Design Document markdown.""" import markdown2 from xhtml2pdf import pisa from pathlib import Path SCRIPT_DIR = Path(__file__).parent # Read the markdown file md_text = (SCRIPT_DIR / "MAC-API-Design-Document.md").read_text(encoding="utf-8") # Convert markdown to HTML with extras html_body = markdown2.markdown( md_text, extras=["tables", "fenced-code-blocks", "code-friendly", "header-ids", "break-on-newline"] ) # Professional CSS styling css = """ @page { size: A4; margin: 2cm 2.2cm 2cm 2.2cm; @frame footer { -pdf-frame-content: footerContent; bottom: 0.5cm; margin-left: 2.2cm; margin-right: 2.2cm; height: 1cm; } } body { font-family: Helvetica, Arial, sans-serif; font-size: 10pt; line-height: 1.55; color: #1a1a1a; } h1 { font-size: 22pt; color: #0d1b2a; border-bottom: 2.5pt solid #1b4965; padding-bottom: 6pt; margin-top: 28pt; margin-bottom: 14pt; page-break-after: avoid; } h2 { font-size: 16pt; color: #1b4965; border-bottom: 1pt solid #c8d6e5; padding-bottom: 4pt; margin-top: 22pt; margin-bottom: 10pt; page-break-after: avoid; } h3 { font-size: 13pt; color: #2a6f97; margin-top: 16pt; margin-bottom: 8pt; page-break-after: avoid; } h4 { font-size: 11pt; color: #2a6f97; margin-top: 12pt; margin-bottom: 6pt; } table { width: 100%; border-collapse: collapse; margin: 10pt 0 14pt 0; font-size: 9pt; } th { background-color: #1b4965; color: #ffffff; padding: 7pt 8pt; text-align: left; font-weight: bold; border: 0.5pt solid #1b4965; } td { padding: 6pt 8pt; border: 0.5pt solid #d0d7de; vertical-align: top; } tr:nth-child(even) td { background-color: #f6f8fa; } code { font-family: Courier, monospace; font-size: 8.5pt; background-color: #f0f2f5; padding: 1pt 3pt; border-radius: 2pt; color: #c7254e; } pre { background-color: #f0f2f5; border: 0.5pt solid #d0d7de; border-radius: 4pt; padding: 10pt 12pt; font-family: Courier, monospace; font-size: 8pt; line-height: 1.45; overflow-x: auto; margin: 8pt 0 12pt 0; page-break-inside: avoid; } pre code { background-color: transparent; padding: 0; color: #1a1a1a; font-size: 8pt; } blockquote { border-left: 3pt solid #1b4965; margin: 10pt 0; padding: 8pt 14pt; background-color: #f0f7fb; font-style: italic; color: #333; } hr { border: none; border-top: 1.5pt solid #1b4965; margin: 20pt 0; } a { color: #1b4965; text-decoration: none; } p { margin: 4pt 0 8pt 0; } ul, ol { margin: 4pt 0 10pt 16pt; padding: 0; } li { margin-bottom: 3pt; } strong { color: #0d1b2a; } /* Title page styling */ .cover-title { font-size: 36pt; color: #0d1b2a; font-weight: bold; text-align: center; margin-top: 120pt; margin-bottom: 10pt; } .cover-subtitle { font-size: 16pt; color: #1b4965; text-align: center; margin-bottom: 40pt; } .cover-meta { font-size: 11pt; color: #555; text-align: center; line-height: 1.8; } """ # Build complete HTML document cover_page = """