You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for your package and this help for me to connect my local mac machine POS USB printer from flutter web. Everything good and i able to connect and send the data. but the problem is, the data that is being printed in printer is not readable character. so i need to convert the data into correct format and send to transferOut api.
Code is below.
static Future<void> connectUsbPrinter() async {
bool canUse = canUseUsb();
if (canUse) {
//* connect the specific USB printer device using the device's vendor id and product id.
UsbDevice requestDevice = await usb.requestDevice(
RequestOptions(
filters: [
RequestOptionsFilter(
vendorId: 0x04B8,
productId: 0x0E02,
),
],
),
);
await requestDevice.open();
await requestDevice.reset();
int firstInterfaceNumber =
requestDevice.configuration?.interfaces[0].interfaceNumber ?? 0;
await requestDevice.claimInterface(firstInterfaceNumber);
//* i am using dart-pdf package to generate the pdf document with 80 mm size and if i print manually
//*the generated pdf from flutter web, then all is good. but my expectation is send the pdf data to printer directly but
based on the current limitation in dart-pdf, printing package, i was unable to send data to local printer directly from flutter web.
//*but later based on some research, i ended up your package to connect the local printer from flutter web using webusb package.
//* The below function actually generates the pdf and respond the data in Uint8List type. now i want to send this data to
//* your transferOut api to printer in printable format.
final pdfDataInUint8ListType = await generatePdf(PdfPageFormat.roll80);
//* here is the link for dart-pdf pacakge how to connect the printer and how to convert Uint8List type printable format.
[https://github.com/DavBfr/dart_pdf/wiki/Document-Output#using-another-plugin]
//* this is the api from web_usb to send data to device. This is how i am sending today but its not printing in readable
//* format.
var usbOutTransferResult = await requestDevice.transferOut(1, pdfDataInUint8ListType);
//* all of them are working and i am able to connect the local machine device from flutter web and able to send the data
//*but the problem is, data is being printed as undisplayable character in paper. as per dart-pdf page example, i see below code to convert from Uint8List to some printable format. I dont know whether i can use this to trasferOut api from this code returns List<int> type but transferOut api expected TypedData. your makeBlock function returns array length error.
Future<void> printTicket() async {
final printer = PrinterNetworkManager('192.168.0.123');
final res = await printer.connect();
if (res != PosPrintResult.success) {
throw Exception('Unable to connect to the printer');
}
final profile = await CapabilityProfile.load();
final generator = Generator(PaperSize.mm80, profile);
var ticket = <int>[];
await for (var page
in Printing.raster(await _generateTicket(), dpi: dpi)) {
final image = page.asImage();
ticket += generator.image(image);
ticket += generator.feed(2);
ticket += generator.cut();
}
printer.printTicket(ticket);
printer.disconnect();
}
//* ideally the question is, how to convert the Uint8List to printable character type and send to transferOut api. transferOut api accepts TypedData type to send data.
}
Attached is the impage & pdf that i am expecting to print using POS USB device using web_usb package. Dp80_print_demo.pdf
But it prints as below. The reason could be i am not doing the correct conversation when i call transferOut method. So, i am asking how to adapt "Unit8List" type to "TypedData" type to send the data to printer. As i mentioned, i followed your example with the function that you wrote "makeBlock" function but its not working for printer as your example is for some other device. so can you give example of how to do it for USB printer? It would be really helpful. Thank you!.
Hi,
First of all, thanks for your package and this help for me to connect my local mac machine POS USB printer from flutter web. Everything good and i able to connect and send the data. but the problem is, the data that is being printed in printer is not readable character. so i need to convert the data into correct format and send to transferOut api.
Code is below.
I looked at your example in the below link. but it seems to be ledger nano device. i want to do the same for USB printer.
https://github.com/woodemi/web_usb.dart/blob/master/example/lib/ledger_nano_s_page.dart
Can you please share example of converting Uint8List type TypedData so that it can print in readable character?
Appreciate your response.
The text was updated successfully, but these errors were encountered: