CodeMinion / another_brother

Another Brother Flutter SDK
BSD 3-Clause "New" or "Revised" License
21 stars 19 forks source link

Flutter App doesn't print PDF on my Brother PT-900WC Wrong Label #88

Closed PromILLEPapst123 closed 2 months ago

PromILLEPapst123 commented 2 months ago

Hello, i'am writing an application where i get an pdf from my api and i safe it in the project folder with the packages "path" and "pathprovider". It works very good so far. Now i have Problems to print on my printer vias usb. The printer is connected via dockingstation to my android tablet. With the "usb_serial" package i get the path of the dev\usb path where the printer is connected. Is there any Option where i can set this path as the path to print for the printer. I searched for Android Java applications and found one example:

UsbManager usbManager = (UsbManager) cxt.getSystemService(Context.USB_SERVICE);
                    UsbDevice usbDevice = printer.getUsbDevice(usbManager);

Or is there any other solution to fix this problem.

CodeMinion commented 2 months ago

Hi @PromILLEPapst123 ,

Thanks for reaching out about this. Could I trouble you to share a bit more details like what code you are currently using to print?

Thanks in advance,

PromILLEPapst123 commented 2 months ago

Hi,

i actually tried to fixed it by myself and found a way to do so. When i start my application i list all devices with the usb_serial package. With selecting the printer i also set the printer and printerInfo in a provider to print anywhere while the application is opened. My main problem was that i was alwasy getting the error: Wrong_Label. To fix this problem i did this:

if ((_brotherPrinterAndroid != null) && (_brotherPrinterAndroid!.productName == 'PT-P900W')) { Printer printer = Printer(); PrinterInfo printerInfo = PrinterInfo();

  printerInfo.printerModel = Model.PT_P900W;
  printerInfo.printMode = PrintMode.FIT_TO_PAPER;
  printerInfo.port = Port.USB;
  printerInfo.orientation = brother.Orientation.LANDSCAPE;
  **printerInfo.labelNameIndex = PT.ordinalFromID(PT.W36.getId());**
  printerInfo.labelMargin = 0;
  printerInfo.printQuality = PrintQuality.HIGH_RESOLUTION;
  printerInfo.isAutoCut = false;
  printerInfo.isHalfCut = true;
  printerInfo.isCutAtEnd = true;
  printerInfo.isCutMark = true;

  bool temp = await printer.setPrinterInfo(printerInfo);

  /*
  await printer.startCommunication();
  await printer.endCommunication();
   */
  printer.startCommunication();
  printer.endCommunication();

  return printer;

  instead of this:

   if ((_brotherPrinterAndroid != null) &&
    (_brotherPrinterAndroid!.productName == 'PT-P900W')) {
  Printer printer = Printer();
  PrinterInfo printerInfo = PrinterInfo();

  printerInfo.printerModel = Model.PT_P900W;
  printerInfo.printMode = PrintMode.FIT_TO_PAPER;
  printerInfo.port = Port.USB;
  printerInfo.orientation = brother.Orientation.LANDSCAPE;
  **printerInfo.labelNameIndex = PT.W36.getID();**
  printerInfo.labelMargin = 0;
  printerInfo.printQuality = PrintQuality.HIGH_RESOLUTION;
  printerInfo.isAutoCut = false;
  printerInfo.isHalfCut = true;
  printerInfo.isCutAtEnd = true;
  printerInfo.isCutMark = true;

  bool temp = await printer.setPrinterInfo(printerInfo);

  /*
  await printer.startCommunication();
  await printer.endCommunication();
   */
  printer.startCommunication();
  printer.endCommunication();

  return printer;