Commit e0794bfa authored by Bogdan Vacaliuc's avatar Bogdan Vacaliuc
Browse files

Improve PDF page-break behavior and typography



Reduce base font (11pt→10pt), margins, and spacing so the report
fits cleanly in 6 pages. Add CSS break-inside/break-after/break-before
rules to keep tables, code blocks, list items, and headings from
being orphaned across page boundaries.

Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
parent b53c5e44
Loading
Loading
Loading
Loading
−2.29 KiB (56.7 KiB)

File changed.

No diff preview for this file type.

+72 −22
Original line number Diff line number Diff line
@@ -8,44 +8,79 @@ from weasyprint import HTML
CSS = """
@page {
    size: letter;
    margin: 1in 0.75in;
    margin: 0.8in 0.65in;
    @bottom-center {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9pt;
        font-size: 8pt;
        color: #666;
    }
}
body {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.5;
    font-size: 10pt;
    line-height: 1.45;
    color: #222;
}

/* --- Page-break controls --- */
h1, h2, h3 {
    break-after: avoid;    /* don't orphan a heading at page bottom */
}
h2 {
    break-before: auto;    /* allow (but don't force) break before h2 */
}
table {
    break-inside: avoid;   /* keep tables on one page when possible */
    break-before: avoid;   /* keep table with its preceding paragraph */
}
pre {
    break-inside: avoid;   /* keep code blocks together */
}
li {
    break-inside: avoid;   /* keep list items together */
}
p {
    orphans: 3;            /* at least 3 lines at bottom of page */
    widows: 3;             /* at least 3 lines at top of page */
}
p + table {
    break-before: avoid;   /* table immediately after paragraph stays with it */
}
strong {
    break-after: avoid;    /* bold labels stay with following content */
}

/* --- Headings --- */
h1 {
    font-size: 18pt;
    font-size: 16pt;
    border-bottom: 2px solid #333;
    padding-bottom: 6pt;
    padding-bottom: 5pt;
    margin-top: 0;
    margin-bottom: 8pt;
}
h2 {
    font-size: 14pt;
    font-size: 13pt;
    border-bottom: 1px solid #999;
    padding-bottom: 4pt;
    margin-top: 20pt;
    padding-bottom: 3pt;
    margin-top: 16pt;
    margin-bottom: 6pt;
}
h3 {
    font-size: 12pt;
    margin-top: 16pt;
    font-size: 11pt;
    margin-top: 12pt;
    margin-bottom: 4pt;
}

/* --- Tables --- */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 12pt 0;
    font-size: 10pt;
    margin: 8pt 0;
    font-size: 9pt;
}
th, td {
    border: 1px solid #aaa;
    padding: 4pt 8pt;
    padding: 3pt 6pt;
    text-align: left;
}
th {
@@ -55,39 +90,54 @@ th {
tr:nth-child(even) {
    background-color: #f6f6f6;
}

/* --- Inline code --- */
code {
    font-family: "Courier New", Courier, monospace;
    font-size: 9.5pt;
    font-size: 8.5pt;
    background-color: #f0f0f0;
    padding: 1pt 3pt;
    padding: 1pt 2pt;
    border-radius: 2pt;
}

/* --- Code blocks --- */
pre {
    background-color: #f0f0f0;
    padding: 8pt 12pt;
    border-radius: 4pt;
    padding: 6pt 10pt;
    border-radius: 3pt;
    border: 1px solid #ddd;
    overflow-x: auto;
    font-size: 9pt;
    line-height: 1.4;
    font-size: 8pt;
    line-height: 1.35;
    margin: 6pt 0;
}
pre code {
    background-color: transparent;
    padding: 0;
}

/* --- Block quotes --- */
blockquote {
    border-left: 3pt solid #ccc;
    padding-left: 12pt;
    padding-left: 10pt;
    color: #555;
    margin-left: 0;
}

/* --- Misc --- */
strong {
    color: #111;
}
hr {
    border: none;
    border-top: 1px solid #ccc;
    margin: 16pt 0;
    margin: 12pt 0;
}
p {
    margin: 4pt 0 6pt 0;
}
ul, ol {
    margin: 4pt 0 6pt 0;
}
"""