#!/usr/bin/env python3 """ Generate PDF report from markdown with embedded screenshots """ import markdown2 from weasyprint import HTML, CSS from pathlib import Path import base64 def embed_image_as_base64(image_path): """Convert image to base64 for embedding in HTML""" try: with open(image_path, 'rb') as img_file: img_data = base64.b64encode(img_file.read()).decode('utf-8') return f"data:image/png;base64,{img_data}" except Exception as e: print(f"Warning: Could not embed image {image_path}: {e}") return "" def create_html_with_screenshots(md_content, screenshots_dir): """Convert markdown to HTML and embed screenshots""" # Convert markdown to HTML html_content = markdown2.markdown(md_content, extras=['tables', 'fenced-code-blocks']) # Find all screenshot references and embed them screenshot_files = { 'homepage-full-page.png': 'Homepage - Full Page View', 'about-page.png': 'About Us Page', 'vision-program-page.png': 'Vision Program Page', 'protege-program-page.png': 'Protégé Program Page', 'calendar-page.png': 'Calendar Page', 'contact-page.png': 'Contact Us Page', 'gala-page.png': 'Graduation Gala Page' } # Build screenshots section HTML screenshots_html = '
\n

APPENDIX: PAGE SCREENSHOTS

\n' for filename, caption in screenshot_files.items(): img_path = Path(screenshots_dir) / filename if img_path.exists(): img_base64 = embed_image_as_base64(img_path) if img_base64: screenshots_html += f'''

{caption}

{caption}

File: {filename}

''' # Replace the appendix section with embedded images if 'APPENDIX: SCREENSHOTS' in html_content: html_content = html_content.split('APPENDIX: SCREENSHOTS')[0] + screenshots_html else: html_content += screenshots_html return html_content def create_pdf_report(md_file, output_pdf, screenshots_dir): """Generate PDF report from markdown file""" print(f"Reading markdown file: {md_file}") with open(md_file, 'r', encoding='utf-8') as f: md_content = f.read() print("Converting markdown to HTML with embedded screenshots...") html_body = create_html_with_screenshots(md_content, screenshots_dir) # Create complete HTML document with styling html_template = f''' Vision Leadership ADA Assessment Report {html_body} ''' print("Generating PDF...") HTML(string=html_template).write_pdf(output_pdf) print(f"✅ PDF report generated successfully: {output_pdf}") if __name__ == '__main__': # File paths md_file = 'VISIONLEADERSHIP_ADA_ASSESSMENT_REPORT_2025-10-03.md' output_pdf = 'VISIONLEADERSHIP_ADA_ASSESSMENT_REPORT_2025-10-03.pdf' screenshots_dir = 'screenshots' # Generate PDF create_pdf_report(md_file, output_pdf, screenshots_dir)