Spaces:
Running
Running
| from playwright.sync_api import sync_playwright | |
| import os | |
| def generate_pdf(html_path, output_path="report.pdf"): | |
| with sync_playwright() as pw: | |
| browser = pw.chromium.launch() | |
| page = browser.new_page() | |
| # Normalize path for Playwright | |
| safe_path = html_path.replace("\\", "/") | |
| page.goto(f"file:///{safe_path}") | |
| page.pdf( | |
| path=output_path, | |
| format="A4", | |
| print_background=True, | |
| ) | |
| browser.close() | |
| return output_path |