ekasetiawans / flutter_bluetooth_printer_plugin

MIT License
21 stars 36 forks source link

convert pdf to images #11

Closed maxzod closed 1 year ago

maxzod commented 1 year ago

works fine on 2.3.0 ✔ after upgrade to flutter_bluetooth_printer: ^2.6.3 the api for FlutterBluetoothPrinter.printImage changed no i have to pass a List<int> instead of image from package image

i tried to use image.getBytes()

the code i use to convert pdf to image

Future<Image> convertPdfUnit8ListToImage(
  Uint8List docBytes, [
  double? width,
]) async {
  final watch = Stopwatch()..start();
  final document = await x.PdfDocument.openData(docBytes);
  final page = await document.getPage(1);
  final image = await page.render(
    width: width ?? page.width * 3,
    height: page.height * 3,
    format: x.PdfPageImageFormat.png,
  );
  page.close();
  final img = decodeImage(image!.bytes.buffer.asUint8List());
  watch.stop();

  log('it took ${watch.elapsed.inSeconds} Seconds');
  if (img != null) return img;
  throw Exception('Could not decode image');
}

but the package print a dark image blow i will before update : صورة واتساب بتاريخ 2022-12-18 في 16 46 35 (2) after update and use bytes صورة واتساب بتاريخ 2022-12-18 في 16 46 35

ekasetiawans commented 1 year ago

the List image is raw ARGB bytes, i recommends to use Receipt widget instead