renderPage method

Future<Uint8List> renderPage({
  1. required int pageIndex,
  2. required int width,
  3. required int height,
  4. Color backgroundColor = Colors.white,
  5. bool drawAnnot = true,
  6. bool drawForm = true,
  7. CPDFPageCompression compression = CPDFPageCompression.png,
})

Renders a specific page of the document as an image. Parameters:

  • pageIndex The index of the page to render.
  • width The width of the rendered image in pixels.
  • height The height of the rendered image in pixels.
  • backgroundColor The background color to use when rendering the page. Default is white. only Android Platform
  • drawAnnot Whether to draw annotations on the rendered page. Default is true. only Android Platform
  • drawForm Whether to draw form fields on the rendered page. Default is true. only Android Platform
  • compression The compression format for the rendered image. Default is PNG. only Android Platform example:
var pageIndex = 0; // The index of the page to render
Size size = await document.getPageSize(pageIndex);
Uint8List imageData = await document.renderPage(pageIndex: pageIndex, width: size.width, height: size.height);

Implementation

Future<Uint8List> renderPage(
    {required int pageIndex,
    required int width,
    required int height,
    Color backgroundColor = Colors.white,
    bool drawAnnot = true,
    bool drawForm = true,
    CPDFPageCompression compression = CPDFPageCompression.png}) async {
  final result = await _channel.invokeMethod('render_page', {
    'page_index': pageIndex,
    'width': width,
    'height': height,
    'background_color': backgroundColor.toHex(),
    'draw_annot': drawAnnot,
    'draw_form': drawForm,
    'compression': compression.name,
  });
  if (result is Uint8List) {
    return result;
  } else if (result is Map && result.containsKey('error')) {
    throw Exception('renderPage failed: ${result['error']}');
  } else {
    throw Exception('renderPage failed: unexpected result type ${result.runtimeType}');
  }
}