24 lines
562 B
Python
24 lines
562 B
Python
|
|
import os
|
|
import sys
|
|
import django
|
|
from django.conf import settings as django_settings
|
|
from django.template.loader import render_to_string
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
|
django.setup()
|
|
|
|
def test_pdf():
|
|
from weasyprint import HTML
|
|
print("Imported weasyprint")
|
|
html_string = "<h1>Test</h1>"
|
|
try:
|
|
pdf = HTML(string=html_string).write_pdf()
|
|
print(f"Success! PDF size: {len(pdf)}")
|
|
except Exception as e:
|
|
print(f"Failed: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_pdf()
|