How to print a file?

Jeanadua

New Member
Licensed User
Longtime User
Hi!!!

Anyone knows how to print a file to a Bluetooth printer?
Is necessary a library to do that?

Regards,

Joan Garcia
 
Hi,

thanks for the answers, but I need a little bit more :sign0085:

1. Is it right, that all STRINGs are UNICODE by default ?

or can i build a string or buffer (byte() array) directly in ANSI ?

2. I found in the help for TextWriter, that I could use another initalize ...

TextWriter1.Initialize(Serial1.OutputStream) use UTF8
TextWriter1.Initialize2(Serial1.OutputStream,"ANSI") -> Java Error
unsupportet charsetexeption ...
TextWriter1.Initialize2(Serial1.OutputStream,"1252") -> Java Error

Where can I read whats the right value ?

3. Whats the best way ?

dim BoldOn() as byte // in ANSI = chr(27)+"E1"
dim BoldOff() as byte // in ANSI = chr(27)+"E0"
dim buffer() as byte
buffer ??? = boldOn + "Überschrift" + boldOff + CRLF ...
TextWriter1.WriteLine(buffer)

- I did not use VB, so the syntax is very strange for me ;-)

or StringBuild ? or a byte array ?
 
Upvote 0
You can get a list of all the encodings supported on a particular device with the SupportedEncodings method in my ByteConverter library.

Thanks Agraham.

Rolf
 
Upvote 0
Thanks a lot.

This will print what I need, bold "Überschrift" and 2 lines later normal "Normaler Text", thats what I need ...
Code: Copy
Sub btnSend_Click
   Dim buffer As StringBuilder
   buffer.Initialize
   buffer.append(Chr(27)).append("E1") ' bold on
   buffer.append("Überschrift")
   buffer.append(Chr(27)).append("E0") ' bold off
   
   If connected Then
      TextWriter1.Initialize2(Serial1.OutputStream,"ISO-8859-1")
       TextWriter1.WriteLine(buffer.ToString)
      TextWriter1.WriteLine("")
      TextWriter1.WriteLine("Normaler Text")
      ' TextWriter1.WriteLine(txtSend.Text)
      TextWriter1.Flush
'      TextWriter1.close
      txtSend.Text = ""
   End If
End Sub


:sign0098:

but one question is still open (for me), what is the best way to handle the control codes ?

As Text with textbuild ...
As Array of Byte or char ?

What do you think ?
 
Last edited:
Upvote 0
Hi,

Thanks for the sample!

Unfortunately, my Star T-301 didn't print the 'Ü' like it should, but printed a block instead. Any idea what could be wrong? I've used the local like posted above.

Edit: after some more testing, I have to replace the 'Ü' with Chr(154). The same goes with all characters above Chr(127),, I have to replace them with another value above 127 to get them right... Somebody has an idea?

Greetings,
Sigurd
 
Last edited:
Upvote 0
Hi,

did you choose the GERMAN language in the printer ?

if this is not possible, than you have to change the german umlauts to the right PC-OEM chr(x), just test it ;-)
 
Upvote 0
Datecs DPP-350

Hi... I have one DATECS DPP-350 Bluetooth printer and Try use serial print to print "TESTESSSSSSSS" withouth sucess... please, help me!!


Code: Copy
Sub Process_Globals
   Dim PrintBuffer As String

   Dim btAdmin As BluetoothAdmin
   Dim dpp350 As Serial
   Dim printer As TextWriter
End Sub

Sub Globals
   Dim Toggla As Toggle
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      btAdmin.Initialize("BlueTooth")
      dpp350.Initialize("Printer")
   End If
   Activity.LoadLayout("MainMenu")
End Sub

Sub Activity_Resume
   StartPrinter
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub



Sub Printer_Connected (Success As Boolean)
   If Success Then
      printer.Initialize(dpp350.OutputStream)
      printer.WriteLine(Chr(27) & "@")
      printer.WriteLine(Chr(27) & "T")
      printer.WriteLine("TESTESSSSSSSSSSSSSS")
      printer.Flush

      printer.Close
      dpp350.Disconnect
      Msgbox("Success","sucesso")
   Else
      If Msgbox2("", "Printer Error","Reprint","Cancel","",Null) = DialogResponse.POSITIVE Then
         StartPrinter
      End If
   End If
End Sub

Sub StartPrinter
   Dim PairedDevices As Map
   Dim L As List
   Dim Res As Int

   ToastMessageShow("Printing.....",True)

   PairedDevices.Initialize

   Try
      PairedDevices = dpp350.GetPairedDevices
   Catch
      Msgbox("Getting Paired Devices","Printer Error")
      printer.Close
      dpp350.Disconnect
   End Try

   If PairedDevices.Size = 0 Then
      Msgbox("Error Connecting to Printer - Printer Not Found","")
      Return
   End If

   If PairedDevices.Size = 1 Then
      Try
         dpp350.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
      Catch
         Msgbox("Connecting","Printer Error")
         printer.Close
         dpp350.Disconnect
      End Try
   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
         dpp350.Connect(PairedDevices.Get(L.Get(Res)))
      End If
   End If   
End Sub
 
Upvote 0
No error...

No Error appears... My phone found printer on bluetooth, connect with this printer, however nothing is printed...

This printer uses ESC/POS commands...

I try use the serial sample, with another cell I connect and chat normally... however when I connect the serial sample with printer... the bluetooth connect... I write something and I click 'SEND"... nothing is printed on printer...

This printer commes with a .JAR file... I put this jar file on B4A library and B4A not found this library... I can use only a JAR file (without XML file) in B4A?

The jar is attached...

Sorry my bad English, I'm from Brazil!
 
Upvote 0
Eclipse

This printer, have a Printer Sample writed in ECLIPSE with this library attached... the sample writed in Eclipse works perfectly... print TEXT, BARCODE, etc...

However I want print using B4A because all my projects are writting in B4A and I not like Eclipse IDE...
 
Upvote 0
Printer Sample

I will read now about how to use this JAR in my project...

This attach have a ECLIPSE SAMPLE (that use the JAR attached previously).

This example (Printer Sample) work perfectly on my phone with dpp-350 printer...

If someone can help me how use this jar file in B4A project I'll be very grateful!
 
Upvote 0
problem Solved

Hi Guys...

Problem solved!

The problem are not in software... the problem is in DIP SWITCH setup in hardware (below battery).

To work correct with bluetooth serial samples the SWITCH have to set in mode off (all 4 switch)

Thank's!
 
Upvote 0
Back
Top