Can I print with windows phone 8 using Bluetooth to a portable printer?

ngonzalez picture ngonzalez · Jan 4, 2013 · Viewed 8.8k times · Source

I am developing an app on windows phone 8. This app must print tickets using a mobile printer like a Zebra MZ 220 Mobile Printer.

I have been googling trying to get information about printing to a bluetooth printer using windows phone 8 but there is not to much information.

My fear is to have to start a new development in another mobile operating system like android, just because wp8 does not support printing on bluetooth.

Is there any example about it? Is there any portable printer compatible with Microsoft Windows Phone 8?

Answer

Fontanka16 picture Fontanka16 · Feb 28, 2013

This code works for me on a Zebra 420 paired with a Nokia 820.

 private async void PrintStuff()
        {
            string command = "^XA^LH30,30^F020,10^AD^FDHello World^FS^XZ";
            Byte[] buffer = new byte[command.Length];
            buffer = StringToAscii(command);

            PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
            var pairedDevices = await PeerFinder.FindAllPeersAsync();

            if (pairedDevices.Count == 0)
            {
                Debug.WriteLine("No paired devices were found.");
            }
            else
            {
                PeerInformation selectedDevice = pairedDevices[0];
                StreamSocket socket = new StreamSocket();
                await socket.ConnectAsync(selectedDevice.HostName, "1");                
                await socket.OutputStream.WriteAsync(WindowsRuntimeBufferExtensions.AsBuffer(buffer));
            }
        }