"""
return html
def generate_pdf(data: dict) -> bytes:
"""Generate a PAC-style PDF report using WeasyPrint."""
try:
from weasyprint import HTML, CSS
except ImportError:
raise RuntimeError("WeasyPrint not installed. Run: pip install weasyprint>=60.0")
score = data.get("accessibility_score", 0)
grade = grade_from_score(score)
sc = data.get("severity_counts", {})
issues = [i for i in data.get("issues", []) if not i.get("dismissed")]
checks = data.get("checks_performed", [])
filename = data.get("filename", "Unknown")
total_pages = data.get("total_pages", 0)
now = datetime.now().strftime("%Y-%m-%d %H:%M")
matterhorn = data.get("matterhorn_summary", {})
breakdown = data.get("score_breakdown", {})
is_adjusted = breakdown.get("adjusted", False)
score_color = "#059669" if score >= 80 else "#d97706" if score >= 60 else "#dc2626"
sections_html = ""
# Build accessible Matterhorn table with scope attrs
if matterhorn and matterhorn.get("checkpoints"):
mh_rows = ""
for cp in matterhorn["checkpoints"]:
status = cp["status"]
if status == "PASS" and cp.get("manual"):
status_cell = '
Manual Pass
'
elif status == "PASS":
status_cell = '
PASS
'
elif status == "FAIL":
status_cell = '
FAIL
'
else:
status_cell = '
Not tested
'
mh_rows += f'
CP{cp["id"]} {cp["name"]}
{cp["how"]}
{status_cell}
'
overall = "FULFILLED" if matterhorn.get("overall_passed") else "NOT FULFILLED"
overall_cls = "pass" if matterhorn.get("overall_passed") else "fail"
sections_html = f"""
Matterhorn Protocol — PDF/UA-1
PDF/UA-1 requirements: {overall}
Matterhorn Protocol checkpoint results
Checkpoint
How
Status
{mh_rows}
"""
if issues:
issue_rows = ""
for iss in issues:
sev = iss.get("severity", "INFO")
issue_rows += f"""
{sev}
{iss.get("category", "")}
{iss.get("page_number") or "—"}
{iss.get("description", "")}
"""
sections_html += f"""
Issues ({len(issues)})
Accessibility issues found in the document
Severity
Category
Page
Description
{issue_rows}
"""
# Compliance section for PDF
compliance = data.get('wcag_compliance', {})
if compliance:
a_pass = compliance.get('level_a', False)
aa_pass = compliance.get('level_aa', False)
a_cls = 'pass' if a_pass else 'fail'
aa_cls = 'pass' if aa_pass else 'fail'
a_text = '✓ Pass' if a_pass else '✗ Fail'
aa_text = '✓ Pass' if aa_pass else '✗ Fail'
sections_html += f"""
WCAG 2.1 Conformance
WCAG 2.1 Level A: {a_text}
WCAG 2.1 Level AA: {aa_text}
"""
next_steps = data.get('next_steps', [])
if next_steps:
ns_rows = ''
for i, s in enumerate(next_steps, 1):
pl = {1: 'Critical', 2: 'Error', 3: 'Warning'}.get(s.get('priority', 3), '')
ns_rows += f'