{"library":"weasyprint","code":"from weasyprint import HTML, CSS\n\nhtml_content = \"\"\"\n<!DOCTYPE html>\n<html>\n<head>\n    <title>My Document</title>\n    <style>\n        @page { size: A4; margin: 2cm; }\n        body { font-family: sans-serif; }\n        h1 { color: #336699; }\n        p { line-height: 1.5; }\n    </style>\n</head>\n<body>\n    <h1>Hello, WeasyPrint!</h1>\n    <p>This is a test document generated from HTML and CSS into a PDF.</p>\n    <img src=\"https://weasyprint.org/static/logo.png\" alt=\"WeasyPrint Logo\">\n</body>\n</html>\n\"\"\"\n\n# You can also load from a URL: HTML('https://weasyprint.org/')\n# Or from a file: HTML(filename='my_document.html')\n\n# Create an HTML object from a string\nhtml = HTML(string=html_content)\n\n# Optionally, add external CSS (or inline as shown above)\n# css = CSS(filename='style.css') # or CSS(string='body { font-size: 12pt; }')\n\n# Write the PDF to a file\nhtml.write_pdf('output.pdf')\n\nprint(\"PDF generated successfully as output.pdf\")","lang":"python","description":"This quickstart demonstrates how to convert a simple HTML string with embedded CSS into a PDF file using WeasyPrint. You can also load HTML from a URL or a local file. The `write_pdf` method saves the rendered document to the specified filename.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}