Printing

drmover

Member
Licensed User
Longtime User
Hello,

Is there any way to send data to a printer using Basic4Android? Any library?

Can it be done from WebView or even from a regular screen?

Thank you,
Elad.
 

Olaan

Expert
Licensed User
Longtime User
I have ever printed by google cloud printing. you must have cloud printer or
computer attached printer and set cloud printer via crome browser before.
save file needed for print and use another application help to print.
Theera
 
Upvote 0

Amalkotey

Active Member
Licensed User
Longtime User
Upvote 0

drmover

Member
Licensed User
Longtime User
Reply

Thank you for your reply.

Is there any way to print directly to the printer? without being depend on Internet connection or desktop computer?

Thank you,
Elad.
 
Upvote 0

Tom Christman

Active Member
Licensed User
Longtime User
As nfordbscndrd indicated, there are H-P and other printers that do tablet printing somewhat. I've got an app for basketball coaches, and I created the scoresheet on a canvas. Using "can1.Bitmap.WriteToStream(out1,100,"PNG")", the screen is saved. Then using "Gallery" or another photo viewer-program, you can print to one of the tablet printers. Hope this helps.
Tom
 
Upvote 0

boastrike

Member
Licensed User
Longtime User
Timwil,

If you have any tips on how you accomplished that would be greatly appreciated. I have been trying to get Bluetooth communication to some portable thermal printers with no luck yet.

Thanks, Jim
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
Hi Jim

I am using a Citizen CMP10 and CMP20 - thermal POS Printer. First I pair it with my Android device then when I want to print I run the StartPrinter sub to connect then use pprint to send a line to the printer - like in the saleprint sub.

I am also exploring using the BTAdmin to automatically find the printer for me so I might not have to manually pair them together


B4X:
Sub Process_Globals
   Dim cmp20 As Serial
   Dim printer As TextWriter
End Sub

Sub Printer_Connected (Success As Boolean)
   If Success Then
      ToastMessageShow("Connected successfully", False)
      printer.Initialize(cmp20.OutputStream)
   Else
      Msgbox(LastException.Message, "Error connecting.")
   End If
End Sub

Sub StartPrinter
   Dim PairedDevices As Map
   Dim l As List
   Dim res As Int

   Try
      PairedDevices = cmp20.GetPairedDevices
   Catch

   End Try

   If PairedDevices.Size = 1 Then
      cmp20.Connect(PairedDevices.Get(PairedDevices.GetKeyAt(0)))
   Else
      l.Initialize

      For i = 0 To PairedDevices.Size - 1
         l.Add(PairedDevices.GetKeyAt(i))
      Next

      res = InputList(l, "Choose device", -1)

      If res <> DialogResponse.CANCEL Then
         cmp20.Connect(PairedDevices.Get(l.Get(res)))
      End If
   End If
End Sub

Sub pprint(xString As String)
   printer.WriteLine(xString)
   printer.Flush
End Sub

Sub SalePrint_Click
   For xc=0 To slList1.Size - 1
      pprint(slList1.GetItem(xc))
   Next
End Sub
 
Last edited:
Upvote 0

ruellesmith

New Member
I am having a hard time also to print my documents and I am looking forward to see some help in here. I have tried also to use Bluetooth communication to some portable thermal printers but I still don't have luck.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
What type of printer are you trying to print to?

What are you trying to print?

I have a POS program running on Android devices (phones and tablets) that store data in a SQLite database and print to a battery operated thermal printer.
 
Upvote 0

Joggi

New Member
Licensed User
Longtime User
Hi timwil

May i know how did you do it? the printing of your POS application to thermal printers using bluetooth. I am new to basic 4 android. I hope you can help me.

Thanks in advance
 
Upvote 0

drmover

Member
Licensed User
Longtime User
Hello,

Thank you for your reply.

Can it print from the WebView?

My main problem is to print HTML from WebView.

Thanks,
Elad.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
Where are you trying to print to?

The printers I am using are receipt printers and I send information directly to them. Any special codes must be in the string of characters that I send.

If you are talking about HTML you would need to have some conversion to the printer language
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Presently printing HTML direct to a wifi printer using 3rd party app PrinterShare. Works well for personal use.
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
So what is it you are trying to do?

The PrintShare software would be doing the formatting - or converting the html into the format the printer can understand.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
There is a program called printbot that you can print from your phone to an IP printer. I think this is what he is trying to do. Be able to print something out. It's a little program that runs and gives you to option to print things instead of showing them onscreen.
 
Upvote 0
Top