# PyWebLayout ## Project Status | Badge | Description | |-------|-------------| |  | **Test Coverage** - Percentage of code covered by unit tests | |  | **Documentation Coverage** - Percentage of code with docstrings | |  | **License** - Project licensing information | A Python library for HTML-like layout and rendering. > 📋 **Note**: Badges show results from the commit referenced in the URLs. Red "error" badges indicate build failures for that specific step. ## Description PyWebLayout is a Python library for HTML-like layout and rendering to paginated images. It provides a flexible page rendering system with support for borders, padding, text layout, and HTML parsing. ## Key Features ### Page Rendering System - 📄 **Flexible Page Layouts** - Create pages with customizable sizes, borders, and padding - 🎨 **Styling System** - Control backgrounds, border colors, and spacing - 📐 **Multiple Layouts** - Support for portrait, landscape, and square pages - 🖼️ **Image Output** - Render pages to PIL Images (PNG, JPEG, etc.) ### Text and HTML Support - 📝 **HTML Parsing** - Parse HTML content into structured document blocks - 🔤 **Font Support** - Multiple font sizes, weights, and styles - 🎨 **Dynamic Font Families** - Switch between Sans, Serif, and Monospace fonts on-the-fly - ↔️ **Text Alignment** - Left, center, right, and justified text - 📖 **Rich Content** - Headings, paragraphs, bold, italic, and more - 📊 **Table Rendering** - Full HTML table support with headers, borders, and styling - 🔘 **Interactive Elements** - Buttons, forms, and links with callback support ### Architecture - **Abstract/Concrete Separation** - Clean separation between content structure and rendering - **Extensible Design** - Easy to extend with custom renderables - **Type-safe** - Comprehensive type hints throughout the codebase ## Installation ```bash pip install pyWebLayout ``` ## Quick Start ### Basic Page Rendering ```python from pyWebLayout.concrete.page import Page from pyWebLayout.style.page_style import PageStyle # Create a styled page page_style = PageStyle( border_width=2, border_color=(200, 200, 200), padding=(30, 30, 30, 30), # top, right, bottom, left background_color=(255, 255, 255) ) page = Page(size=(600, 800), style=page_style) # Render to image image = page.render() image.save("my_page.png") ``` ### HTML Content Parsing ```python from pyWebLayout.io.readers.html_extraction import parse_html_string from pyWebLayout.style import Font # Parse HTML to structured blocks html = """
First paragraph with bold text.
Second paragraph with more content.
""" base_font = Font(font_size=14) blocks = parse_html_string(html, base_font=base_font) # blocks is a list of structured content (Paragraph, Heading, etc.) ``` ## Visual Examples The library supports various page layouts and configurations:
Page Styles![]() Different borders, padding, and backgrounds |
HTML Content![]() Parsed HTML with various text styles |
Page Layouts![]() Portrait, landscape, and square formats |
Table Rendering![]() HTML tables with headers and styling |
Interactive Elements![]() Buttons, forms, and callback binding |
|
🆕 Pagination & PageBreak![]() Multi-page documents with explicit and automatic breaks |
🆕 Link Navigation![]() All 4 link types: Internal, External, API, Function |
🆕 Comprehensive Forms![]() All 14 form field types with validation |
|
🆕 Dynamic Font Family Switching![]() Switch between Sans, Serif, and Monospace fonts instantly |
|