Search code examples
pdfflutterprintingpngbarcode

flutter png and then create PDF file to printer


I am working in new flutter project that capture a widget to PNG image with a barcode and a few text like this one and send the data to the printer via native code. But I had many issues. For example printing is too slow with ios devices (android print speed is ok). So I decide to print from PDF for ios and I have a few questions:

  1. which package do I have to use for printing the PDF.
  2. also can u provide me with the correct code for converting to PDF

thank you


Solution

  • You can check out this package:

    https://pub.dev/packages/printing

    examples from the package:

    final doc = pw.Document();
    
    doc.addPage(pw.Page(
      pageFormat: PdfPageFormat.a4,
      build: (pw.Context context) {
        return pw.Center(
          child: pw.Text('Hello World'),
        ); // Center
      })); 
    

    then

    await Printing.layoutPdf(
      onLayout: (PdfPageFormat format) async => doc.save());
    

    hope it works for you.