render method

Future<PdfPageImage?> render({
  1. required int width,
  2. required int height,
  3. PdfPageFormat format = PdfPageFormat.PNG,
  4. String? backgroundColor,
  5. Rect? cropRect,
  6. int quality = 100,
  7. @visibleForTesting bool removeTempFile = true,
})

Render a full image of specified PDF file.

width, height specify resolution to render in pixels. As default PNG uses transparent background. For change it you can set backgroundColor property like a hex string ('#FFFFFF') format - image type, all types can be seen here PdfPageFormat cropRect - render only the necessary part of the image quality - hint to the JPEG and WebP compression algorithms (0-100)

Implementation

Future<PdfPageImage?> render({
  required int width,
  required int height,
  PdfPageFormat format = PdfPageFormat.PNG,
  String? backgroundColor,
  Rect? cropRect,
  int quality = 100,
  @visibleForTesting bool removeTempFile = true,
}) =>
    _lock.synchronized<PdfPageImage?>(() async {
      if (document.isClosed) {
        throw PdfDocumentAlreadyClosedException();
      } else if (isClosed) {
        throw PdfPageAlreadyClosedException();
      }

      return PdfPageImage._render(
        pageId: id,
        pageNumber: pageNumber,
        width: width,
        height: height,
        format: format,
        backgroundColor: backgroundColor,
        crop: cropRect,
        quality: quality,
        removeTempFile: removeTempFile,
      );
    });