resumebuilder / test_weasyprint.py.old
sakthi07's picture
pushing to hugging face
ab028ac
#!/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 = """
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial; padding: 20px; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Test PDF Generation</h1>
<p>This is a test of WeasyPrint PDF generation.</p>
</body>
</html>
"""
# 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()