kakzaki / blue_thermal_printer

Working with thermal printer via bluetooth (Flutter)
MIT License
164 stars 205 forks source link

Facing issue while data is long in QR code . #196

Closed vijayvaghela72 closed 7 months ago

vijayvaghela72 commented 10 months ago
Screenshot 2023-11-01 at 2 41 57 PM
vijayvaghela72 commented 10 months ago

bluetooth.isConnected;

  // Convert the QR code Uint8List to a base64-encoded bitmap
  await bluetooth.printCustom("Diesel QR Code", 50, 50);
  await bluetooth.printCustom("------------------------", 50, 50);
  await bluetooth.printNewLine();
  await bluetooth.printCustom("Date : $date", 50, 50);
  await bluetooth.printNewLine();
  await bluetooth.printCustom("Trip No. : $tripNo", 50, 50);
  await bluetooth.printNewLine();
  await bluetooth.printCustom("------------------------", 50, 50);
  await bluetooth.printNewLine();
  await bluetooth.printQRcode(jsonEncode(qrDataString), 250, 250, 1);
  await bluetooth.printNewLine();
  await bluetooth.printCustom("------------------------", 50, 50);
  await bluetooth.printCustom("Powered by AeonX Digital", 50, 50);

  // code for print a data to printer

  await bluetooth.printNewLine();
  await bluetooth.printNewLine();
  await bluetooth.printNewLine();

  // Print another blank line (space)
  await bluetooth.printNewLine();

  await bluetooth.paperCut();

  this is my code 
vijayvaghela72 commented 10 months ago

await bluetooth.printQRcode(jsonEncode(qrDataString), 250, 250, 1);

i have added side of 250 * 250

but when string to large then it's print small QR as i share in photo .

vijayvaghela72 commented 10 months ago

please provide me solution for this .

vijayvaghela72 commented 10 months ago

when data is large it's print small QR and QR is not scannable .🥲

vijayvaghela72 commented 10 months ago

Hello team!

please provide help on issue,

@juliocbcotta , @maurovanetti , @mvanvu , @ricardochen , @kakzaki , @ziakhan110 @ziakhan110 @flutter-painter @hmtuan196 @wmattei @tauqeerkhattak @knight-dev

need your help !

Thank You in advance 🙂!

flutter-painter commented 10 months ago

Please provide this data example so it can be reproduced. What does the json look like if you put it in a dedicated object ?

final jsonEncoded = jsonEncode(qrDataString);

How do you build this QR ?

vijayvaghela72 commented 10 months ago

this is my

String qrDataString = "{"T_no":"1699245740","T_date":"06/11/2023","supervisor":"Super Admin","sending_p":"21","sending_p_D":"[GB01] - BOFFA - MINING (GB01)","receving_p":"25","receving_p_D":"[GB05] - KOKAYA - PORT (GB05)","material":"14","material_D":"[11006091] - RB LUMPS 90-120 MM","remarks":"okay","vehical_N":"5","vehical_D":"GJ01BV3021","mining_C_ID":"30","mining_C_D":"TREMPE TRANSPORT","vehical_TW":"null","vehical_C":"100"}"

if similaly i am passing large data in this map variable ,

like this ,

{"T_no":"1699246062","T_date":"06/11/2023","supervisor":"Super Admin","sending_p":"22","sending_p_D":"[GB03] - BOFFA - MINING (GB03)","receving_p":"23","receving_p_D":"[GB02] - KOKAYA - PORT (GB02)","material":"14","material_D":"[11006091] - RB LUMPS 90-120 MM","remarks":"dikfifififidjs5djdtfofhzysigkx namaste namaste ndifjdidudixyfozyfuaogydpdyfodoamaste ","vehical_N":"5","vehical_D":"GJ01BV3021","mining_C_ID":"30","mining_C_D":"TREMPE TRANSPORT","vehical_TW":"null","vehical_C":"100"}

the getting small QR

vijayvaghela72 commented 10 months ago
Screenshot 2023-11-06 at 10 19 48 AM

there is to much size difference in both QR .

@flutter-painter

simplay if data is large means string length is large then small QR code , if string length is small QR code size is large .

vijayvaghela72 commented 10 months ago

therefore small QR is difficult to scan .please help me

vijayvaghela72 commented 10 months ago

@flutter-painter

flutter-painter commented 10 months ago

Hi Vijay,

Thank you for providing more context. Since this seems an urgent issue could you consider the two following workarounds ?

Setting a maximum length to your text fields son that qr code stays below the ceiling.

Making a 2nd qr code if the first one will not be able to contain all info.

This is only to buy you time to dig deeper in the qr making process. Anyhow you will need a string max length since qr can only contain à certain amount of info and the wider they are the harder it is to scan.

vijayvaghela72 commented 10 months ago

Thank you for instance reply ,

when i am trying increase this width and height value to more than 250 it's not print anything ,

await bluetooth.printQRcode(jsonEncode(qrDataString), 250, 250, 1);

2 different QR not possible in my case i have to maintain every thing in one single QR but main issue is when data increase then QR size is decrease. if in slip there is enough size to expand but it's not working getting small QR code .

how can i increase size of QR . is it possible ?

flutter-painter commented 10 months ago

Everything is possible as long as you put in the efforts.

The Java bit that handles qr creation is in

android/src/main/java/id/kakzaki/blue_thermal_printer/BlueThermalPrinterPlugin.java

It seems to be

BitMatrix bitMatrix = multiFormatWriter.encode(textToQR, BarcodeFormat.QR_CODE, width, height); BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); Bitmap bmp = barcodeEncoder.createBitmap(bitMatrix);

Which gives no clue about qr code Size. Note the height and width settings are just wrappers added by hmtuan196. I dont think they will help you.

Though you will need to setup a max length for your strings, I understand that the experienced threshold is not acceptable for you.

Here are two options I See :

  1. Rework this Java code to control qr code generation / rendering
  2. Make the qr code out of this lib using another package, save this qr locally as a png, add the png to your printing process. See https://github.com/kakzaki/blue_thermal_printer/blob/master/example/lib/testprint.dart

You may want to delete qr code after printing You might be able to print images from memory instead of handling needed persistence.

github-actions[bot] commented 8 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.