Eddayy / flutter_star_prnt

Flutter plugin for star printer
GNU General Public License v3.0
15 stars 60 forks source link

TSP100 Alignment issues #11

Closed pradeep1806 closed 3 years ago

pradeep1806 commented 3 years ago

Hello ,

Is there any way to align properly ?

Below method does not work fine with different kind of words.

It's really very difficult to make proper design with dynamic content .

Please suggest.If i use font , it does not reflect in the .

My Code and i have attached the sample receipt . 50ce2dcd-8f0c-443f-8a9e-3aae41babe70

PrintCommands commands = PrintCommands();

commands.appendBitmapText(
    text: "     ${getStoreName(ordersViewModel, sale)}       \n",
    alignment: StarAlignmentPosition.Center,
    fontSize: 30);

commands.appendBitmapText(
    text: "${getLine1(ordersViewModel, sale)}\n",
    alignment: StarAlignmentPosition.Center,
    fontSize: 25);

commands.appendBitmapText(
    text: "${getLine2(ordersViewModel, sale)}\n",
    alignment: StarAlignmentPosition.Center,
    fontSize: 25);

commands.appendBitmapText(
    text: "${getLine3(ordersViewModel, sale)}\n",
    alignment: StarAlignmentPosition.Center,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"INVOICE NO : ${sale.id}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"ORDER ID : ${sale.offline_order_id}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"DATE : ${ordersViewModel.getDateTime(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"COUNTER : ${ordersViewModel.getRegisterName(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"CUSTOMER : ${ordersViewModel.getCustomerName(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);
commands.appendBitmapText(
    text: "${"SALESPERSON : ${ordersViewModel.getFrontLiner(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);
commands.appendBitmapText(
    text: "----------------------------------------\n");

commands.appendBitmapText(text: "Qty     Price     Discount     Total\n");

Map<String, dynamic> rasterMap1 = HashMap();

for (SaleItem saleItem in sale.sale_items) {
  commands.appendBitmapText(
      text:
          "${ordersViewModel.getProductNameInDetail(saleItem, unitsOfMeasure)}\n",
      alignment: StarAlignmentPosition.Left,
      fontSize: 25);

  commands.appendBitmapText(
      text: "${getProductUpc(productsMap, saleItem.product_id)}\n",
      alignment: StarAlignmentPosition.Left,
      fontSize: 25);

  if (saleItem.discount_id != null &&
      saleItem.total_discount_amount != null &&
      double.parse(saleItem.total_discount_amount) > 0) {
    Discount discount = ordersViewModel.getDiscountFromId(
        saleItem.discount_id, allDiscounts);
    if (discount != null) {
      commands.appendBitmapText(
          text: "${discount.name}\n",
          alignment: StarAlignmentPosition.Left,
          fontSize: 25);
    }
  }
  commands.appendBitmapText(
    text:
        "${ordersViewModel.getProductQty(saleItem, unitsOfMeasure)}     ${ordersViewModel.getPricePerUnit(saleItem, unitsOfMeasure)}     ${ordersViewModel.getDiscountAmountOfItem(saleItem)}       ${ordersViewModel.getPricePerUnitPaid(saleItem)}  \n",
  );
}

commands.appendBitmapText(
    text: "${"GROSS : ${ordersViewModel.getSubTotal(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"DISCOUNT : ${ordersViewModel.getDiscountAmount(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"TAX : ${ordersViewModel.getTaxAmount(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.appendBitmapText(
    text: "${"TOTAL : ${ordersViewModel.getTotalAmount(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

if (sale.payments != null && sale.payments.length > 0) {
  for (Payment payment in sale.payments) {
    commands.appendBitmapText(
        text: "${"${payment.payment_type.name} :${payment.amount}"}\n",
        alignment: StarAlignmentPosition.Right,
        fontSize: 25);
  }
}
commands.appendBitmapText(
    text: "${"NO. OF ITEMS : ${ordersViewModel.getNoOfItems(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);
commands.appendBitmapText(
    text:
        "${"NO. OF UNITS : ${ordersViewModel.getTotalNoOfItems(sale)}"}\n",
    alignment: StarAlignmentPosition.Left,
    fontSize: 25);

commands.push(rasterMap1);
commands.openCashDrawer(1);
commands.appendCutPaper(StarCutPaperAction.PartialCut);
var printStatus = await StarPrnt.print(
    portName: model.port,
    emulation: 'StarGraphic',
    printCommands: commands);

I want to print my PDF file which is aligned properly. If use appendBytes , it is not working.

Please suggest alternate way for below , to make it more dynamic. Map<String, dynamic> rasterMap = { 'appendBitmapText': " Star Clothing Boutique\n" + " 123 Star Road\n" + " City, State 12345\n" + "\n" + "Date:MM/DD/YYYY Time:HH:MM PM\n" + "--------------------------------------\n" + "SALE\n" + "SKU Description Total\n" + "300678566 PLAIN T-SHIRT 10.99\n" + "300692003 BLACK DENIM 29.99\n" + "300651148 BLUE DENIM 29.99\n" + "300642980 STRIPED DRESS 49.99\n" + "30063847 BLACK BOOTS 35.99\n" + "\n" + "Subtotal 156.95\n" + "Tax 0.00\n" + "--------------------------------------\n" + "Total 156.95\n" + "--------------------------------------\n" + "\n" + "Charge\n" + "156.95\n" + "Visa XXXX-XXXX-XXXX-0123\n" + "Refunds and Exchanges\n" + "Within 30 days with receipt\n" + "And tags attached\n", };

Eddayy commented 3 years ago

Its because appendbitmaptext converts the text to an image, and alignment arguments is for the text images. I recommend you switch to appendbitmapwidget or appendbitmapbyte in version 2.2.0 for better formatting