Forum Xamarin.Android

Print string from xamarin android app to printer

Wirg0Wirg0 USMember

Hi everyone,

I have to print a ticket with string, qrcode and image.

I have actually a TSP100-ECO from starmicronics but the library doesn't work ...

What kind of printer are you using to print from android app ?
And can you share your code please ?

Thanks !


  • Wirg0Wirg0 USMember

    Nobody can help me ? ...

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
  • Wirg0Wirg0 USMember

    My device is in 4.1 Jelly Bean ... not in 4.4 KitKat

  • cvaldezcvaldez USMember
    edited February 2017

    Hi, this run in Android 4.0.3 and upper. At first, it could be a sad trip for printing but you would need to purchase some more things for doing it:
    1. A print server device (is a little device which can receive print commands and it is plugged on the usb port of your printer and configurated for connect to your wi-fi network)
    2. Your Ticket printer documentation (this is for the commands that are only for that printer)
    3. Your Android Device from 4.0.3 version

    At this point you won't need more than configure your print server with an IP and a Port, to access this through your cellphone by a Socket like the next example:

       private async Task Print()
            await Task.Run (() => 
                    //As you will see, all depends on your printer commands
                     Socket socket = new Socket(YOUR_PRINTSERVER_IP, YOUR_PRINSERVER_TCP_PORT);
                     PrintWriter pw = new PrintWriter (socket .OutputStream, true);
                     //here is the beginning of printing
                     pw.Write(0x1B); //Example of command to start a printer
                     pw.Print("THIS IS YOUR AWESOME TEXT FOR PRINT");
                     pw.Write(0x0C); //here you release the paper
                     pw.Write(0x40); //finish printing
                     pw.Flush ();
                     pw.Close ();
                     socket.Close ();
            catch(SocketException ex)
            Console.WriteLine("SocketError: "+ex.Message);

    And your principal advantage is an easier installation and it will receive all the print requests from all the devices which run your application like a local machine

  • ljdevljdev INMember
    @cvaldez I had tried out your code. But didn't worked for me. Is there anything specifically need to be done for Android. I tried providing print permission still same. Worked when tried to print an image from device using HP print client providing ip. No error and exceptions and tried debugging and saw connection status as true for socket. Any hint or advice on this is very helpful.
Sign In or Register to comment.