wapPdfPageFormat function

PdfPageFormat wapPdfPageFormat(
  1. String paper,
  2. String orient
)

PdfPageFormat reuses the same normalizePaper/isLandscape detection as the on-screen/HTML print path, so all three (screen width, @page size, PdfPageFormat) never disagree. @@@ 2026-08-10 fix: a custom size (e.g. "8.5x5.5") now builds the PdfPageFormat directly from its inch value.

Implementation

PdfPageFormat wapPdfPageFormat(String paper, String orient) {
  final custom = customPaperSizeInches(paper);
  if (custom != null) {
    final (w, h) = custom;
    final base = PdfPageFormat(w * PdfPageFormat.inch, h * PdfPageFormat.inch);
    return isLandscape(orient) ? base.landscape : base.portrait;
  }
  final PdfPageFormat base;
  switch (normalizePaper(paper)) {
    case 'letter':
      base = PdfPageFormat.letter;
    case 'legal':
      base = PdfPageFormat.legal;
    case 'A3':
      base = PdfPageFormat.a3;
    case 'A5':
      base = PdfPageFormat.a5;
    default:
      base = PdfPageFormat.a4;
  }
  return isLandscape(orient) ? base.landscape : base.portrait;
}