fromPdfBytes static method

Future<Uint8List> fromPdfBytes(
  1. Uint8List pdfBytes
)

Implementation

static Future<Uint8List> fromPdfBytes(Uint8List pdfBytes) async {
  // rasterize PDF to image for thermal printer
  final pages = await Printing.raster(pdfBytes, dpi: 203).toList();

  final doc = pw.Document();

  for (final page in pages) {
    final image = pw.MemoryImage(await page.toPng());
    doc.addPage(
      pw.Page(
        build: (_) => pw.Center(child: pw.Image(image)),
      ),
    );
  }

  return doc.save();
}