renderPageAsBytes method
Create empty bitmap and render page onto it The bitmap always uses 4 bytes per pixel. The first byte is always double word aligned. The byte order is BGRx (the last byte unused if no alpha channel) or BGRA. flags FPDF_ANNOT | FPDF_LCD_TEXT
Implementation
Uint8List renderPageAsBytes(int width, int height,
{int backgroundColor = 268435455, int rotate = 0, int flags = 0,}) {
if (_page == nullptr) {
throw PdfiumException(message: 'Page not load');
}
// var backgroundStr = "FFFFFFFF"; // as int 268435455
final w = width;
final h = height;
const startX = 0;
final sizeX = w;
const startY = 0;
final sizeY = h;
// Create empty bitmap and render page onto it
// The bitmap always uses 4 bytes per pixel. The first byte is always
// double word aligned.
// The byte order is BGRx (the last byte unused if no alpha channel) or
// BGRA. flags FPDF_ANNOT | FPDF_LCD_TEXT
bitmap = pdfium.FPDFBitmap_Create(w, h, 0);
pdfium.FPDFBitmap_FillRect(bitmap!, 0, 0, w, h, backgroundColor);
pdfium.FPDF_RenderPageBitmap(
bitmap!, _page!, startX, startY, sizeX, sizeY, rotate, flags,);
// The pointer to the first byte of the bitmap buffer The data is in BGRA format
buffer = pdfium.FPDFBitmap_GetBuffer(bitmap!);
//stride = width * 4 bytes per pixel BGRA
//var stride = pdfium.FPDFBitmap_GetStride(bitmap);
//print('stride $stride');
final list = buffer!.asTypedList(w * h * 4);
return list;
}