Jak tisknout z webové stránky na bluetooth tiskárně Android

Pro tisk z webové aplikace můžete použít aplikaci:

APP & WEB POS PRINTER DRIVER

V této aplikaci nalinkujte svou připojenou bluetooth tiskárnu. Můžete použít třeba cenově výhodnou Birch BMC02

Po nalinkování již můžete tisknout přímo ze svých stránek. Pro odkaz tisku použijte klasický a tag:

<a href="com.fidelier.printfromweb://$biguhw$Hello World$intro$$small$This is small letter$intro$->$intro$->$intro$->$intro$$intro$$intro$$intro$$cut$$intro$">Print Test from WEB </a>

Test: Print Test from WEB

ESC/POS URL-encoding

An ESC/POS printers get a stream of text embedding some „escape“ formatting code, following the ESC/POS „standard“ original defined by Epson. The problem is that ESC codes contains are also non printable chars. To URL-encode ESC/POS commands, Luis Blatta propose two solutions:

  • DOLLAR_SIGN_ENCODING

    ESC_POS_DATA is a string containing ESC/POS commands represented by $symbol$ specified by the following table:

    $ Escape code Description
    $small$ small size
    $smallh$ small size with double hight
    $smallw$ small size with double width
    $smallhw$ small size with double hight and width
    $smallu$ small size underline
    $smalluh$ small size with double hight underline
    $smalluw$ small size with double width underline
    $smalluhw$ small size with double hight and width underline
    $big$ big size
    $bigh$ big size with double hight
    $bigw$ big size with double width
    $bighw$ big size with double hight and width
    $big$ big size, underline
    $bigh$ big size with double hight, underline
    $bigw$ big size with double width, underline
    $bighw$ big size with double hight and width, underline
    $cut$ cut the paper
    $drawer$ open the first drawer
  • DOT_ENCODING

    This is a more versatile, complete solution for URL-encode any ESC/POS command: developer must represent each ‚non printable‘ char with a special encoding, enclosing the decimal representation of the code with special sign (%C2%B7 URL-encoded), so by example

    • the char with decimal value 27 become ▪27▪,
    • and ESC/POS escape sequence to cut the paper ‚ESC m‘, is equal to 1B6D in hexadecimal and is equal to 27 109 in decimal, become: ▪27▪▪109▪
    • at least the complete string to cut the paper is: ▪27▪▪109▪▪13▪▪10▪

Print from your Android App (interactive user action)

Create your ESC data using the helpers Create an Android Intent using Add your ESC data as a “Data” extra Start the intent. You can be printing in minutes with just a couple lines of code. It’s as simple as creating your intent, adding your ESC formatted string and start the (service) intent.

Example:

String dataToPrint="$big$This is a printer test$intro$posprinterdriver.com$intro$$intro$$cut$$intro$";

Intent intentPrint = new Intent();

intentPrint.setAction(Intent.ACTION_SEND);
intentPrint.putExtra(Intent.EXTRA_TEXT, dataToPrint);
intentPrint.setType("text/plain");

this.startActivity(intentPrint);

Examples

Let consider an interesting example: you want to print this receipt of an ecommerce order:


ORDINE 20
del 10-10-2015 alle ore 10:00
pizzeria d'albertis (cod. 663)

1 pizze
01 x capresina                   6.50

2 bibite
01 x coca cola                   1.50
01 x mezza gassata               0.50
-------------------------------------
confezionamento per asporto      0.50
fattorino a domicilio            1.00
totale euro                     10.00
-------------------------------------

consegna a domicilio
10-10-2015             alle ore 13:30

Caterina de Michel
salita san giorgio 6/9
16100 genova
tel. 1234567901

using the mode A encoding, to print the above text with a final paper cut also:

$ curl -X POST http://www.posprinterdriver.com/api/v1/api/sendDataToPrinter? \
               linkcode=12345&data=\
ORDINE 20\
del 10-10-2015 alle ore 10:00\
pizzeria d'albertis (cod. 663)\
\
1 pizze\
01 x capresina                   6.50\
\
2 bibite\
01 x coca cola                   1.50\
01 x mezza gassata               0.50\
-------------------------------------\
confezionamento per asporto      0.50\
fattorino a domicilio            1.00\
totale euro                     10.00\
-------------------------------------\
\
consegna a domicilio\
10-10-2015             alle ore 13:30\
\
Caterina de Michel\
salita san giorgio 6/9\
16100 genova\
tel. 1234567901\
\
\$intro$ 

https://github.com/solyaris/posprinterdriver