savePageAsJpg method
Saves the loaded page as jpg image
Throws an PdfiumException if no page is loaded. Returns a instance of PdfiumWrap
Implementation
PdfiumWrap savePageAsJpg(String outPath,
{int? width,
int? height,
int backgroundColor = 268435455,
double scale = 1,
int rotate = 0,
int flags = 0,
bool flush = false,
int qualityJpg = 100,}) {
if (_page == nullptr) {
throw PdfiumException(message: 'Page not load');
}
// var backgroundStr = "FFFFFFFF"; // as int 268435455
final w = ((width ?? getPageWidth()) * scale).round();
final h = ((height ?? getPageHeight()) * scale).round();
final bytes = renderPageAsBytes(w, h,
backgroundColor: backgroundColor, rotate: rotate, flags: flags,);
final Image image = Image.fromBytes(
width: w,
height: h,
bytes: bytes.buffer,
order: ChannelOrder.bgra,
numChannels: 4,
);
// save bitmap as PNG.
File(outPath)
.writeAsBytesSync(encodeJpg(image, quality: qualityJpg), flush: flush);
return this;
}