DantSu / ESCPOS-ThermalPrinter-Android

Useful library to help Android developpers to print with (Bluetooth, TCP, USB) ESC/POS thermal printer.
MIT License
1.22k stars 370 forks source link

How can I print this ImageView? #120

Closed Msantos0266 closed 3 years ago

Msantos0266 commented 3 years ago

LinearLayout barcode1 = findViewById(R.id.barcode);

        ImageView iv = new ImageView(MainActivity.this);

        String barcode_data = "010000000100";

        // barcode image
        try {
            Bitmap barCode = encodeAsBitmap(barcode_data, BarcodeFormat.CODE_128, 350, 120);
            // bitmap.getRowBytes();
            iv.setImageBitmap(barCode);

        } catch (WriterException e) {
            e.printStackTrace();
        }

// iv.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // barcode1.addView(iv);

        SimpleDateFormat format = new SimpleDateFormat("'on' yyyy-MM-dd 'at' HH:mm:ss");
        EscPosPrinter printer = new EscPosPrinter(printerConnection, 203, 48f, 32);
        printer
                .printFormattedText(
                        "[C]<img>" + iv + "</img>\n" +
                                "[L]\n" +
                                "[C]<u><font size='big'>ORDER N°045</font></u>\n" +
                                "[L]\n" +
                                "[C]<u type='double'>" + format.format(new Date()) + "</u>\n" +
                                "[C]\n" +
                                "[C]================================\n" +
                                "[L]\n" +
                                "[L]<b>BEAUTIFUL SHIRT</b>[R]9.99€\n" +
                                "[L]  + Size : S\n" +
                                "[L]\n" +
                                "[L]<b>AWESOME HAT</b>[R]24.99€\n" +
                                "[L]  + Size : 57/58\n" +
                                "[L]\n" +
                                "[C]--------------------------------\n" +
                                "[R]TOTAL PRICE :[R]34.98€\n" +
                                "[R]TAX :[R]4.23€\n" +
                                "[L]\n" +
                                "[C]================================\n" +
                                "[L]\n" +
                                "[L]<u><font color='bg-black' size='tall'>Customer :</font></u>\n" +
                                "[L]Raymond DUPONT\n" +
                                "[L]5 rue des girafes\n" +
                                "[L]31547 PERPETES\n" +
                                "[L]Tel : +33801201456\n" +
                                "\n" +
                                "[C]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
                                "[L]\n" +
                                "[C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>\n"
                );
DantSu commented 3 years ago

you forgot to use "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(iv) + "</img>\n"

DantSu commented 3 years ago

<barcode> tag has type 128. https://github.com/DantSu/ESCPOS-ThermalPrinter-Android#barcode

Msantos0266 commented 3 years ago

Cannot resolve method 'bitmapToHexadecimalString(android.widget.ImageView)

when I use this codes "[C]" + PrinterTextParserImg.bitmapToHexadecimalString(iv) + "\n"

DantSu commented 3 years ago

Have you import PrinterTextParserImg class ?

Harisul44 commented 2 years ago

how to implement

                        rs=st.executeQuery(Query);
                        while (rs.next())
                        {

"[L]\n" + "[L]BEAUTIFUL SHIRT[R]9.99e\n" + "[L] + Size : S\n" +

                        }