Xamarin Forms Receipt Printing (Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

ความคิดเห็น • 84

  • @zackcoolman1
    @zackcoolman1 4 ปีที่แล้ว +6

    How do i print image?
    print text has no problem on my app

  • @janakipriya7204
    @janakipriya7204 ปีที่แล้ว

    hi i made webview i want to print that using android print manager on print preview page the webview contains white border at all place how to remove

  • @najeebvannp
    @najeebvannp 3 ปีที่แล้ว

    Can I use the same method Print() for printing an image instead of IList

  • @mohsenmohamed2281
    @mohsenmohamed2281 4 ปีที่แล้ว +1

    Why you made a class in each platform with the same implementation ?
    Why you didn't make just one class at the shared project and call the print() function from the button ?

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว +1

      to show the use of dependency service. You could use the same code on the shared project and that would work the same way. Thanks

  • @mraak324
    @mraak324 3 ปีที่แล้ว +1

    I have done this using Bluetooth connectivity print is genrate but issue is half print coming first time then next time I am giving aging print comnad then last print half portion coming in current print
    Can you suggest me what I have to do for resolving the issue?

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      It is a bit difficult to suggest something without looking at your code.

    • @mraak324
      @mraak324 3 ปีที่แล้ว

      @@MrNawshad
      public async Task Print(string deviceName, IList linesToPrint)
      {
      using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
      {
      BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices
      where bd?.Name == deviceName
      select bd).FirstOrDefault();
      try
      {
      using (BluetoothSocket bluetoothSocket = device?.
      CreateRfcommSocketToServiceRecord(
      UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")))
      {
      List outputList = new List();
      foreach (string txt in linesToPrint)
      {
      // Convert the strings to list of bytes
      outputList.AddRange(System.Text.Encoding.UTF8.GetBytes(txt));
      // Add ECS/POS Print and line feed command
      outputList.Add(0x0A); ;
      }
      bluetoothSocket?.Connect();
      if (bluetoothSocket.IsConnected)
      {
      Thread.Sleep(200);
      try
      {
      bluetoothSocket.OutputStream.Write(outputList.ToArray());
      }
      catch (Exception e)
      {
      }
      //bluetoothSocket.OutputStream.Position = 0;
      //System.Threading.Thread.Sleep(5000);
      bluetoothSocket.OutputStream.Flush();
      bluetoothSocket.OutputStream.Close();
      bluetoothSocket.OutputStream.Dispose();
      // bluetoothSocket.OutputStream.Position =0;
      bluetoothSocket.Close();
      bluetoothSocket.Dispose();
      }
      }
      }
      catch (Exception exp)
      {
      throw exp;
      }
      }
      }

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      @@mraak324 use try catch finally for instance try {
      }catch {
      }finally{
      bluetoothSocket.OutputStream.Flush();
      bluetoothSocket.OutputStream.Close();
      bluetoothSocket.OutputStream.Dispose();
      // bluetoothSocket.OutputStream.Position =0;
      bluetoothSocket.Close();
      bluetoothSocket.Dispose();
      }
      see if this works. good luck. and let me know your result. thanks.

    • @mraak324
      @mraak324 3 ปีที่แล้ว

      @@MrNawshad hi
      Issue has been resolved I have update my printer firmware now print is coming perfectly
      Thank for your quick support
      Can we print pdf using above code ?

    • @By_Bestboy
      @By_Bestboy ปีที่แล้ว

      Hi. Could you please tell me how you obtain a bluetoothsocket in IOS?. Thank you.

  • @vivekhariharganj
    @vivekhariharganj 3 ปีที่แล้ว

    Thanks For Showing example. Please help me to print xamarin page , or if I have list of product object

  • @venuqsconsultants3138
    @venuqsconsultants3138 3 ปีที่แล้ว

    when connecting to psocket.connect it is showing mistake "operation blocked "

  • @GianAlmeyda
    @GianAlmeyda 2 ปีที่แล้ว +1

    good contribution, it works for me, but I have problems cutting the paper, can you help me?

    • @MrNawshad
      @MrNawshad  2 ปีที่แล้ว +1

      for full cut send this command
      { 0x1d, 0x56, 0x00 }; // Full cut paper

    • @GianAlmeyda
      @GianAlmeyda 2 ปีที่แล้ว

      @@MrNawshad How do I apply it after outputList.Add(0x1d);
      outputList.Add(0x56);
      outputList.Add(0x00);

    • @GianAlmeyda
      @GianAlmeyda 2 ปีที่แล้ว +1

      @@MrNawshad Thanks, I was able to apply it, I was getting complicated,
      pSocket.Send(outputList.ToArray());
      pSocket.Send(PrinterCommands.CUT_PAPER);

  • @drackkeyner
    @drackkeyner 3 ปีที่แล้ว

    Amazing tutorial bro

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      Glad you like it. Please share this content so others find it useful too. Thanks.

  • @AMIRKHAN-dm2fm
    @AMIRKHAN-dm2fm 4 ปีที่แล้ว +1

    hi please tell me ho to save web view data as pdf ?

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      codemilltech.com/xamarin-forms-e-z-print/

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 4 ปีที่แล้ว

      @@MrNawshad I think this document is supported with older version of Xamarin. Can you please make a tutorial of how to print HTML Page with WebView.

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 4 ปีที่แล้ว

      if you do that this is really helpful for me because my whole project is stuck on it. I have tried a lot of things but useless.

  • @mestutosisptheophile8991
    @mestutosisptheophile8991 3 ปีที่แล้ว

    Can i use the same code to print on an handheld android terminal ????

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว +1

      you need to connect to the device first, the printing commands are same for any devices. thanks.

    • @mestutosisptheophile8991
      @mestutosisptheophile8991 3 ปีที่แล้ว

      @@MrNawshad my terminal have an incorated printer so when i try your code i have the message connection refused.

    • @mestutosisptheophile8991
      @mestutosisptheophile8991 3 ปีที่แล้ว

      @@MrNawshad my android terminal has an incorporated printer but when i try your code by specifiying the ip adress and the port i get : connection refused, please what can i do ???

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว +1

      @@mestutosisptheophile8991 I guess your terminal printer does not have an associated ip address, the ip address you are targeting is for the terminal itself. I think you have to print to this printer through USB communication. if you look into the terminal's manual they usually proved with printer sample code. thanks.

    • @mestutosisptheophile8991
      @mestutosisptheophile8991 3 ปีที่แล้ว +1

      @@MrNawshad i see the manual of the terminal it written android bluetooth terminal, when i activate bluetooth i see the printer name among connected devices, what can i do so ? thank you.

  • @ramanprajapati5266
    @ramanprajapati5266 2 ปีที่แล้ว

    Its not working.Can you update

  • @AMIRKHAN-dm2fm
    @AMIRKHAN-dm2fm 4 ปีที่แล้ว

    How to generate Collection View data in to PDF File in Xamarin.forms can u please make tutorial?

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      Didn’t get what you are asking for.

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 4 ปีที่แล้ว

      @@MrNawshad OK let me explain I want create PDF file of my listview data items like receipt.

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      And where would you like to save it?

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 4 ปีที่แล้ว

      @@MrNawshad I want to save it on my mobile device or send mail

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      Ok. I understand now. Can’t promise on doing a video on it anytime sooner. But will definitely do it once I have my current projects sorted first.

  • @balajidj6184
    @balajidj6184 3 ปีที่แล้ว

    How to print from Android?

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      implement the printer class on android and call the print method from the button event click handler.

  • @redinversati3924
    @redinversati3924 2 ปีที่แล้ว +2

    great!. How can i print pdf, or bitmap, or canvas image usign this socket connetion?

  • @carljohnlopez5425
    @carljohnlopez5425 2 ปีที่แล้ว +1

    great video , this helps me alot , how do you format or put qr code in the output sir? do you have source code of font format and qr code ?

  • @kratos7ism
    @kratos7ism 2 ปีที่แล้ว

    Is there any way to support printing International characters like Greek or Arabic?? English works fine but international characters are printed out like weird symbols.

  • @kratos7ism
    @kratos7ism 2 ปีที่แล้ว

    Thank you so much bro . Your code works perfect . Although i have no problems printing or connecting to a printer it seems that when i use a A4 paper every word you pass as parameters is printed diagonally. Is there any way to fix that ??

  • @skyfiprog7200
    @skyfiprog7200 2 ปีที่แล้ว

    I need to try this, this kind of video is a big help for me, how to pay you if i need help

  • @MrRobravens
    @MrRobravens 2 ปีที่แล้ว

    Bit useless using dependency service for this when the implementation is the same

  • @الانظمةالعربيةللبرمجيات

    Thanks alot

  • @wahyuadhilaksana6457
    @wahyuadhilaksana6457 2 ปีที่แล้ว

    Can I using Printer Brother DCP-T420W , Sir ? thank you

    • @MrNawshad
      @MrNawshad  2 ปีที่แล้ว

      yes, as long as its connected to your local network.

  • @wlickez
    @wlickez 3 ปีที่แล้ว

    Thanks for this tuto, why do you use the 9100 port?

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      hacking-printers.net/wiki/index.php/Port_9100_printing

  • @chickenpoxtv3287
    @chickenpoxtv3287 4 ปีที่แล้ว +1

    Thank you

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว +1

      I m glad you liked it.

    • @chickenpoxtv3287
      @chickenpoxtv3287 4 ปีที่แล้ว

      Can I have a question .. I'm using xamarin in Visual Studio windows version.. I got error using assembly : dependency above in the namespace and dependencyservice ? Can u make a tutorial?

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      @@chickenpoxtv3287 could you be more specific about the error you are encountering. Thanks.

    • @chickenpoxtv3287
      @chickenpoxtv3287 4 ปีที่แล้ว

      @@MrNawshad this code is use to all POS printer brand?

    • @MrNawshad
      @MrNawshad  4 ปีที่แล้ว

      @@chickenpoxtv3287 yeah. As long as the printer supports ESC/POS commands. Which majority of the printer providers support.

  • @jooskesters9472
    @jooskesters9472 3 ปีที่แล้ว

    I followed this guide and my printer is not printing anything :/

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      Make sure you target the right IP address of your printer.

    • @jooskesters9472
      @jooskesters9472 3 ปีที่แล้ว

      @@MrNawshad I connected the printer to my network. Got the ip printed out. Pinged the ip with my laptop to make sure. Than ran my app and tried to print.. Nothing comes out. Do I need certain drivers installed for this on my laptop or sth ?

    • @MrNawshad
      @MrNawshad  3 ปีที่แล้ว

      You need to configure the printer on your network.

    • @jooskesters9472
      @jooskesters9472 3 ปีที่แล้ว

      @@MrNawshad Do you have discord where I can ask you some questions during my troubleshooting ? I understand your response as going to my router page and look for the printer in the settins over there ?

    • @jooskesters9472
      @jooskesters9472 3 ปีที่แล้ว

      In the mean time. I just went to the configuration page of the printer. Logged in, and made sure the settings were right. To sum it up. Network mode: infrastructure mode, 9100 Multi session (tried enable and disable) both don't make a difference for making it work.