printChromeResetCss function

String printChromeResetCss(
  1. String pageSize,
  2. String paper,
  3. String orient
)

@@@ 2026-08-21 The print-only "strip screen decoration + scale font to match the ruler line" stylesheet.

PDF reuses reportCssScreen() (the same one the on-screen preview uses, layout already verified correct), and this adds the two things only printing needs:

(1) Strip the screen-only decoration: gray background, white-paper shadow, border, inter-page gaps.

(2) Derive the font size from the ruler line's character count. The on-screen preview's canvas is paperWidthPx() (750px for A4 portrait), but after @page margin:10mm the actual printable width is only 718px -- the canvas is wider than the printable area, and at the original 13.3px font size, 116 characters need 848px, so the right side gets cut off. This shrinks the font size to "exactly $kRulerChars characters fits the printable width." Also narrows the cell padding (printing doesn't need the screen's click-target padding), buying fields a bit more horizontal room. Capped at 13.3px: when the paper is wide enough (A4 landscape, etc.), the original font size is kept, not enlarged.

Implementation

String printChromeResetCss(String pageSize, String paper, String orient) {
  const mmPerPx = 96.0 / 25.4;
  const marginMm = 20.0; // @page margin 10mm on each side (left + right)
  final printablePx = paperMm(paper, orient) * mmPerPx - marginMm * mmPerPx;
  final usable = printablePx < paperWidthPx(paper, orient)
      ? printablePx
      : paperWidthPx(paper, orient);
  var f = usable / (kRulerChars * kRulerCharWidthRatio);
  if (f > 13.3) f = 13.3;
  final fs = f.toStringAsFixed(2);
  return '''
/* aa @@@ Print: strip screen-only decoration + scale font to match the ruler line ($kRulerChars characters) */
@page { size: $pageSize; margin: 10mm; }
@media print {
  body {
    background: #ffffff;   /* don't print the screen's gray backdrop */
    padding: 0;
  }
  body > table {
    box-shadow: none;      /* paper shadow */
    border: none;
    margin: 0 auto;        /* inter-page gap */
    width: ${usable.toStringAsFixed(0)}px !important;
  }
  body, p, td, th { font-size: ${fs}px; line-height: 1.25; }
  big { font-size: ${(f * 1.35).toStringAsFixed(2)}px; }
  /* printing doesn't need the screen's click-target padding; narrowed for more horizontal room */
  td, th { padding: 1px 3px; }
  /* meaningful background colors (header gray, zebra stripes) must be kept -- browsers filter these out of print by default */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  /* don't let a row split across two pages */
  tr, td, th { page-break-inside: avoid; }
}
/* zz @@@ */
''';
}