sizeForDpi method

({double height, double width}) sizeForDpi(
  1. double dpi
)

Returns the page size in pixels at the given dpi as a named record.

Multiply widthPt and heightPt (both in points, 1/72 inch) by dpi / 72 to obtain pixel dimensions suitable for passing to PdfDocument.renderPageToBytes.

Example: an A4 page (595 × 842 pt) at 150 DPI yields approximately 1239 × 1754 pixels.

dpi must be positive. Returns (width: 0.0, height: 0.0) when dpi is zero or negative.

Implementation

({double width, double height}) sizeForDpi(double dpi) {
  if (dpi <= 0) return (width: 0.0, height: 0.0);
  final scale = dpi / 72.0;
  return (width: widthPt * scale, height: heightPt * scale);
}