placeImage method

bool placeImage(
  1. int pageIndex,
  2. double x,
  3. double y,
  4. Uint8List imageBytes, {
  5. double maxSize = 200,
})

Places imageBytes (PNG or JPEG) centered on (x, y) in page space, maxSize points on its longest side, preserving the image's aspect ratio and capped at 90% of the page so it is never larger than the paper. The centre is the point given, so an image dropped at the edge hangs off the page rather than jumping inward. Returns false when the bytes aren't a decodable PNG or JPEG.

Implementation

bool placeImage(
  int pageIndex,
  double x,
  double y,
  Uint8List imageBytes, {
  double maxSize = 200,
}) {
  final PdfEmbeddableImage image;
  try {
    image = PdfEmbeddableImage.decode(imageBytes);
  } catch (_) {
    return false;
  }
  return _placeDecodedImage(pageIndex, x, y, image, maxSize: maxSize);
}