pageSizeOf function

String pageSizeOf(
  1. String paper,
  2. String orient
)

Builds the value for CSS @page's size, e.g. "letter landscape". @@@ 2026-08-10 fix: a custom size (e.g. "8.5x5.5") now uses its inch value directly as the CSS size, instead of always falling back to A4.

Implementation

String pageSizeOf(String paper, String orient) {
  final custom = customPaperSizeInches(paper);
  if (custom != null) {
    final (w, h) = custom;
    final (pw, ph) = isLandscape(orient) ? (h, w) : (w, h);
    return '${pw}in ${ph}in ${isLandscape(orient) ? 'landscape' : 'portrait'}';
  }
  return '${normalizePaper(paper)} ${isLandscape(orient) ? 'landscape' : 'portrait'}';
}