kechankrisna / flutter_usb_printer

GNU General Public License v3.0
6 stars 45 forks source link

How to print images via USB printer #7

Open shinxxxxwon opened 2 years ago

shinxxxxwon commented 2 years ago

I followed your example and tried printing via USB. Text was fine. But the image is output as text and the layout is messed up.

Does it not support image output by any chance?

I am attaching my source.

connect

_connect(int vendorId, int productId) async {
    bool? returned = false;
    try {
      returned = await flutterUsbPrinter.connect(vendorId, productId);
    } on PlatformException {
      //response = 'Failed to get platform version.';
    }
    if (returned!) {
      setState(() {
        connected = true;
      });
    }
  }

getDevice

_getDevicelist() async {
    List<Map<String, dynamic>> results = [];
    results = await FlutterUsbPrinter.getUSBDeviceList();

    print(" length: ${results.length}");
    setState(() {
      devices = results;
    });
  }

print

_print() async {
    try {
      // var data = Uint8List.fromList(
      //     utf8.encode(" Hello world Testing ESC POS printer..."));
      final ByteData bytes = await rootBundle.load('assets/images/1-1.JPG');
      final Uint8List list = bytes.buffer.asUint8List();
      await flutterUsbPrinter.write(list);
    } on PlatformException {
      print('no printing.');
    }
  }
kechankrisna commented 2 years ago

please take a look the example in link below: https://github.com/kechankrisna/esc_pos_utils it will demonstrate on how to get list to write in printer port.

shinxxxxwon commented 2 years ago

Is the package available only for esc/pos printer? Can it be used with laser printers?

kechankrisna commented 2 years ago

Is the package available only for esc/pos printer? Can it be used with laser printers?

this package is only work with esc pos printer, if you want to try laster printers, I recommend you to use printing