fix(export): render PDF in A4 landscape for 7-column readability
Add @page { size: A4 landscape } to _CSS, reduce font-size to 11px,
and set table-layout: fixed + word-break: break-word so 7 columns
fit without overflow. Unit test asserts the landscape rule is present
in the rendered HTML.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -198,11 +198,12 @@ def render_engagement_csv(
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_CSS = """
|
||||
body { font-family: sans-serif; font-size: 13px; color: #1a1a1a; margin: 40px; }
|
||||
h1 { font-size: 22px; border-bottom: 2px solid #333; padding-bottom: 6px; }
|
||||
h2 { font-size: 17px; margin-top: 32px; color: #333; }
|
||||
table { border-collapse: collapse; width: 100%; margin-bottom: 12px; }
|
||||
th, td { border: 1px solid #ccc; padding: 4px 8px; text-align: left; vertical-align: top; white-space: pre-wrap; }
|
||||
@page { size: A4 landscape; margin: 20mm; }
|
||||
body { font-family: sans-serif; font-size: 11px; color: #1a1a1a; margin: 0; }
|
||||
h1 { font-size: 20px; border-bottom: 2px solid #333; padding-bottom: 6px; }
|
||||
h2 { font-size: 15px; margin-top: 32px; color: #333; }
|
||||
table { border-collapse: collapse; width: 100%; margin-bottom: 12px; table-layout: fixed; }
|
||||
th, td { border: 1px solid #ccc; padding: 3px 6px; text-align: left; vertical-align: top; white-space: pre-wrap; word-break: break-word; }
|
||||
th { background: #e0e0e0; }
|
||||
.meta { color: #555; margin-bottom: 16px; }
|
||||
"""
|
||||
|
||||
@@ -291,6 +291,15 @@ def test_render_engagement_pdf_contains_simulation_table(app) -> None:
|
||||
assert header in html, f"Expected French header '{header}' in HTML"
|
||||
|
||||
|
||||
def test_render_engagement_html_has_landscape_page_rule(app) -> None:
|
||||
from backend.app.services.export import _render_engagement_html
|
||||
|
||||
with app.app_context():
|
||||
eng = _make_engagement()
|
||||
html = _render_engagement_html(eng, [])
|
||||
assert "landscape" in html, "HTML must include A4 landscape @page rule for PDF output"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Defense-in-depth: filename header injection
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user