Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Print HTML from Android on bluetooth printer

$
0
0

Found many answers here and but none helps. So dont mark as duplicate please.

I need to print out styled HTML which contains an image, from Android to Bluetooth printer (Cashino PTP-II) using Xamarin and Visual studio. The only way I think its possible is to convert HTML to image and print out that image (if I am wrong tell me better way please). I know how to print plain text

var listOfDevices = bluetoothAdapter.BondedDevices;

foreach (BluetoothDevice bluetoothDevice in listOfDevices)
{
    if (bluetoothDevice.Name != "PTP-II")
        continue;

    ParcelUuid uuid = bluetoothDevice.GetUuids().ElementAt(0);
    BluetoothSocket socket = bluetoothDevice.CreateInsecureRfcommSocketToServiceRecord(uuid.Uuid);
    socket.Connect();
    outStream = socket.OutputStream;

    //Printing

    byte[] toBytes = Encoding.ASCII.GetBytes("MY TEXT TO PRINT");   
    outStream.Write(toBytes, 0, toBytes.Length);

}

but when I want to print image

byte[] img = webClient.DownloadData("http://test.com/img.png");

outStream.Write(img, 0, img.Length);

comes out only gibberish
printed gibberish

There is printer code which should set printer for printing image mode.

byte[] SELECT_BIT_IMAGE_MODE = new byte[] { 0x1B, 0x2A, 33, 255, 3 };

But I didnt noticed any changes...

Found few JAVA examples but after rewriting JAVA to C# (hope correctly) still, doesn't work.

Thank you for help.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>