Closed antoniopetricc closed 2 years ago
If you can print an image, yes. Use this https://pub.dev/packages/barcode_image Otherwise, try with the pdf plugin: https://github.com/DavBfr/dart_pdf/wiki/Document-Output#using-another-plugin
Thanks for the reply. But if the printer is connected only via usb, what can I do? Is there any way?
I don't know
Ok! I was able to print via my thermal printer. The problem now is the size of the pdf. If the sticker where I print is 50 x 30 mm, how should I set the pdf? Could you give me an example? (With what you gave me from the link it prints me badly!)
Use a
SizedBox(
width: 50 * PdfPageFormat.mm,
height: 30 * PdfPageFormat.mm,
child: BarcodeWidget(
barcode: Barcode.ean13,
data: '12345678'
),
);
If I use 50 and 30 it prints the blank page, to test I also put 500 and 300 and it gives me the giant sticker. What should I put on pageFormat? Now I use "format" but I also saw PdfPageFormat.roll80.
doc.addPage(
Page(
pageFormat: format,
build: (Context context) {
return SizedBox(
width: 500 * PdfPageFormat.mm,
height: 300 * PdfPageFormat.mm,
child: BarcodeWidget(
barcode: Barcode.ean13(drawEndChar: true),
data: '8099807953185',
),
);
},
),
);
I would do:
Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
final pdf = pw.Document();
pdf.addPage(
pw.Page(
pageFormat: PdfPageFormat.roll57.copyWith(
marginTop: 2 * PdfPageFormat.mm,
marginLeft: 3.5 * PdfPageFormat.mm,
marginRight: 3.5 * PdfPageFormat.mm,
marginBottom: 2 * PdfPageFormat.mm,
),
build: (pw.Context context) {
return pw.Center(
child: pw.Wrap(
runSpacing: 2 * PdfPageFormat.mm, // Space between stickers
children: [
pw.SizedBox(
height: 30 * PdfPageFormat.mm,
child: pw.BarcodeWidget(
barcode: pw.Barcode.ean13(drawEndChar: true),
data: '8099807953185',
),
),
pw.SizedBox(
height: 30 * PdfPageFormat.mm,
child: pw.BarcodeWidget(
barcode: pw.Barcode.ean13(drawEndChar: true),
data: '809983425318',
),
),
pw.SizedBox(
height: 30 * PdfPageFormat.mm,
child: pw.BarcodeWidget(
barcode: pw.Barcode.ean13(drawEndChar: true),
data: '809980541185',
),
),
],
),
);
},
),
);
return pdf.save();
}
is it possible to print the barcode with my thermal printer connected via usb?