Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Enterprise-grade research with multi-source synthesis, citation tracking, and verification. 8-phase pipeline with auto-continuation.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/weasyprint_guidelines.md
1# WeasyPrint PDF Generation Guidelines23## Overview45WeasyPrint converts HTML/CSS to PDF. These guidelines ensure professional output without awkward page breaks, orphaned content, or layout issues.67---89## Critical CSS Properties for Page Breaks1011### Prevent Breaking Inside Elements1213```css14/* Apply to containers that should never split across pages */15.executive-summary,16.key-insight,17.warning-box,18.action-box,19.diagram,20.metrics-row,21table {22page-break-inside: avoid;23}2425/* Tables are especially problematic - always prevent breaks */26table {27page-break-inside: avoid;28}2930/* Two-column layouts */31.two-col {32page-break-inside: avoid;33}34```3536### Prevent Orphaned Headers3738```css39/* Headers should never appear at bottom of page without content */40h2, h3, h4 {41page-break-after: avoid;42}43```4445### Prevent Widows and Orphans in Text4647```css48p {49orphans: 3; /* Minimum lines at bottom of page */50widows: 3; /* Minimum lines at top of page */51}52```5354---5556## @page Rules5758### Basic Setup5960```css61@page {62size: A4;63margin: 25mm 20mm 25mm 20mm;6465@top-center {66content: "Report Title";67font-family: Georgia, serif;68font-size: 9pt;69color: #666666;70}7172@bottom-center {73content: counter(page);74font-family: Georgia, serif;75font-size: 10pt;76}77}7879/* Suppress header on first page */80@page :first {81@top-center { content: none; }82}83```8485---8687## Table Design for PDF8889### Avoid Large Tables9091- Keep tables under 8-10 rows when possible92- Split large data sets into multiple smaller tables93- Use `page-break-inside: avoid` on every table9495### Table CSS9697```css98table {99width: 100%;100border-collapse: collapse;101margin: 12pt 0;102font-size: 9pt;103page-break-inside: avoid;104}105106th {107background: #1a1a1a;108color: white;109padding: 8pt 10pt;110text-align: left;111font-size: 8pt;112text-transform: uppercase;113}114115td {116padding: 8pt 10pt;117border-bottom: 0.5pt solid #d0d0d0;118vertical-align: top;119}120```121122---123124## Typography for Print125126### Font Sizes (pt not px)127128Use points for print, not pixels:129130```css131body {132font-family: Georgia, "Times New Roman", Times, serif;133font-size: 10pt;134line-height: 1.6;135}136137h1 { font-size: 22pt; }138h2 { font-size: 14pt; }139h3 { font-size: 11pt; }140141/* Small text */142.citation { font-size: 8pt; }143.footer { font-size: 8pt; }144.bib-entry { font-size: 8pt; }145```146147### Line Height148149- Body text: 1.6-1.7150- Tables: 1.4-1.5151- Bibliography: 1.5152153---154155## Layout Patterns That Work156157### Use `display: table` for Side-by-Side158159Flexbox and Grid have limited WeasyPrint support. Use `display: table`:160161```css162.two-col {163display: table;164width: 100%;165page-break-inside: avoid;166}167168.col {169display: table-cell;170width: 50%;171padding: 10pt;172vertical-align: top;173}174175.col:first-child {176border-right: 0.5pt solid #cccccc;177}178```179180### Metrics Dashboard181182```css183.metrics-row {184display: table;185width: 100%;186border: 1.5pt solid #000000;187page-break-inside: avoid;188}189190.metric {191display: table-cell;192width: 25%;193padding: 12pt 8pt;194text-align: center;195}196```197198---199200## Content Boxes201202### Insight/Warning Boxes203204```css205.key-insight {206background: #f5f5f5;207border-left: 3pt solid #000000;208padding: 10pt 12pt;209margin: 12pt 0;210page-break-inside: avoid;211}212213.warning-box {214background: #1a1a1a;215color: white;216padding: 12pt 15pt;217margin: 12pt 0;218page-break-inside: avoid;219}220```221222### Diagrams223224```css225.diagram {226background: #f5f5f5;227border: 1pt solid #000000;228padding: 12pt;229margin: 12pt 0;230text-align: center;231page-break-inside: avoid;232}233```234235---236237## Bibliography238239```css240.bibliography {241background: #f5f5f5;242padding: 15pt;243margin-top: 20pt;244border-top: 2pt solid #000000;245}246247.bib-entry {248margin-bottom: 8pt;249padding-left: 25pt;250text-indent: -25pt;251font-size: 8pt;252line-height: 1.5;253page-break-inside: avoid;254}255```256257---258259## Common Problems and Solutions260261### Problem: Table Splits Across Pages262263**Solution:** Add `page-break-inside: avoid` to table. If table is too large, split into multiple smaller tables.264265### Problem: Header at Bottom of Page with No Content266267**Solution:** Add `page-break-after: avoid` to all heading elements.268269### Problem: Single Line at Top/Bottom of Page270271**Solution:** Set `orphans: 3` and `widows: 3` on paragraphs.272273### Problem: Flex/Grid Layout Breaks274275**Solution:** Use `display: table` and `display: table-cell` instead.276277### Problem: Images/Diagrams Cut Off278279**Solution:** Add `page-break-inside: avoid` to container.280281### Problem: Margins Too Tight282283**Solution:** Use generous @page margins (25mm top/bottom, 20mm sides).284285---286287## Compact Report Strategy288289To reduce page count while maintaining readability:2902911. **Use 10pt base font** (not 12pt)2922. **Tighter line-height**: 1.5-1.6 instead of 1.82933. **Smaller margins in boxes**: 10pt padding instead of 15pt2944. **Condensed bibliography**: 8pt font, tighter spacing2955. **Two-column layouts** for comparison data2966. **Inline metrics dashboard** rather than full-width cards297298---299300## Validation Checklist301302Before generating PDF, verify:303304- [ ] All tables have `page-break-inside: avoid`305- [ ] All boxed content has `page-break-inside: avoid`306- [ ] Headers have `page-break-after: avoid`307- [ ] Paragraphs have `orphans: 3; widows: 3`308- [ ] No Flexbox or Grid in critical layouts309- [ ] Font sizes in pt, not px310- [ ] @page margins defined311- [ ] Two-column layouts use `display: table`312313---314315## Generation Command316317```bash318weasyprint input.html output.pdf319```320321Options:322- `--presentational-hints` - Respect HTML presentational hints323- `-s stylesheet.css` - Apply external stylesheet324- `--pdf-variant pdf/ua-1` - Generate accessible PDF325