#!/usr/bin/env python3 import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__))) from app import app def test_weasyprint(): with app.app_context(): try: import weasyprint from io import BytesIO # Simple HTML test html_content = """

Test PDF Generation

This is a test of WeasyPrint PDF generation.

""" # Generate PDF pdf_bytes = weasyprint.HTML(string=html_content).write_pdf() # Save test file with open('test_weasyprint.pdf', 'wb') as f: f.write(pdf_bytes) print("WeasyPrint test successful!") print(f"Generated PDF with {len(pdf_bytes)} bytes") return True except Exception as e: print(f"WeasyPrint test failed: {e}") return False if __name__ == "__main__": test_weasyprint()