Render Image
This API allows rendering a specified PDF page as an image. It is useful for generating previews or exporting page content.
The returned data type is Uint8List, which can be used directly for display or saving as an image file.
Method Declaration
dart
Future<Uint8List> renderPage({
required int pageIndex,
required int width,
required int height,
Color backgroundColor = Colors.white,
bool drawAnnot = true,
bool drawForm = true
})
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
pageIndex | int | Yes | The index of the page to render, starting from 0 |
width | int | Yes | Width of the rendered image in pixels |
height | int | Yes | Height of the rendered image in pixels |
backgroundColor | Color | No | Page background color, default is white, Android only |
drawAnnot | bool | No | Whether to render annotations, default true, Android only |
drawForm | bool | No | Whether to render form fields, default true, Android only |
Example Usage
dart
final pageImage = await controller.renderPage(
pageIndex: 0,
width: 1080,
height: 1920,
backgroundColor: Colors.white,
drawAnnot: true,
drawForm: true,
);
// Display the image
Image.memory(pageImage);