Printing to a Zebra LAN Printer

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Printing to a Zebra LAN Printer

Post by AndyGable »

Hi Everyone

I was hoping someone could point me in the right direction

As you are all aware by now I am writing a EPoS application in Gambas (ive started working on the Back office application now) and I need to print some information to a Zebra Label Printer.

Below is the code I use for the Printer (this was crated by a Zebra program so I know it works as it works on my Windows PC)

Code: Select all

I8,A,001
Q280,024
q448
rN
S4
D7
ZT
JF
O
R0,0
f100
N
A181,40,2,4,1,1,N,"2002821"
A434,28,2,4,1,1,N,"F01"
A381,28,2,4,1,1,N,"1001/0052"
A436,134,2,4,2,2,N,"SEE THE ITEM "
A436,90,2,4,2,2,N,"FOR THE PRICE"
A396,50,2,4,1,1,N,"11/01/2020"
A443,245,2,4,1,1,N,"1234567890123456789012345"
A443,223,2,4,1,1,N,"1234567890123456789012345"
A443,201,2,4,1,1,N,"1234567890123456789012345"
A443,179,2,4,1,1,N,"1234567890123456789012345"
A443,157,2,4,1,1,N,"1234567890123456789012345"
P1
I need to print this to the LAN printer that is on 192.168.1.100 Port 9100.

so my question is how do I send data to the printer so it can print? (do I have to add a CUPS driver for it?) or can I send the data direct to the IP address / Port?


Any advice help etc is most welcomed as this was a pain to get working when I was in VB.net lol

Andy
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Printing to a Zebra LAN Printer

Post by sadams54 »

I have used cups to send printer data in my POS application. I am sure you can go direct to port but you are limiting yourself to particular printers that way. The problem with zebra (having worked with their stuff) is that they do not have any linux support.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Printing to a Zebra LAN Printer

Post by AndyGable »

sadams54 wrote: Tuesday 5th December 2023 11:03pm I have used cups to send printer data in my POS application. I am sure you can go direct to port but you are limiting yourself to particular printers that way. The problem with zebra (having worked with their stuff) is that they do not have any linux support.
The way my system is designed I don't print direct to the printer from my software I send data to a module and that does the work so I can have any shelf edge label printer on my system as long as I can make a module for it.

I try to use the usb or serial version of the zebra printers but when you're working in the middle of the shop requesting labels for a new install you are limited to what the customers have.

And yea I know just what you mean by Zebra not having any Linux support (oddly though the have Android support)

Also how would I print the port? I've never done that with Gambas (I assume I would need to open 192.168.1.100:9100 as output or something like that)
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Printing to a Zebra LAN Printer

Post by vuott »

AndyGable wrote: Wednesday 6th December 2023 2:40am Also how would I print the port? I've never done that with Gambas (I assume I would need to open 192.168.1.100:9100 as output or something like that)
Maybe by using Socket Class of gb.net:
http://gambaswiki.org/wiki/comp/gb.net/socket
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Printing to a Zebra LAN Printer

Post by cogier »

Have a look here https://supportcommunity.zebra.com/s/ar ... uage=en_US. I use a Zebra printer at work on Linux, but it is connected via USB. It works well for me. I create PDF files in Gambas and send them to the printer.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Printing to a Zebra LAN Printer

Post by AndyGable »

Does that mean I can still send the raw data to the printer driver like I can with the windows version?

Or would it be better to talk direct to the printer?
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Printing to a Zebra LAN Printer

Post by cogier »

I create a pdf using gb.cairo, then save the image to the /tmp/ folder. I Shell the lp command, see here, with the file name, see below. Job done.

Shell "lp /tmp/my.pdf" Wait


This produces labels like this: -

Image
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Printing to a Zebra LAN Printer

Post by AndyGable »

cogier wrote: Wednesday 6th December 2023 8:19pm I create a pdf using gb.cairo, then save the image to the /tmp/ folder. I Shell the lp command, see here, with the file name, see below. Job done.

Shell "lp /tmp/my.pdf" Wait


This produces labels like this: -

Image
Do you have any examples of how you used the gb.cairo?

Could I use that to print multiple labels across the page?
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Printing to a Zebra LAN Printer

Post by vuott »

AndyGable wrote: Wednesday 6th December 2023 10:23pm Do you have any examples of how you used the gb.cairo?
Here is a simple possible example:
Public Sub Button1_Click()

 Dim png As CairoSvgSurface
 Dim x, y As Integer
 Dim im, im2 As Image

' Specifies the graphic surface to be created for drawing on
' (second and third arguments are in millimeters):
 png = New CairoSvgSurface(Null, 210, 297)

 With Cairo
' Start drawing on the set surface:
   .Begin(png)
' Sets the background color of the entire graphic surface:
   .Source = .ColorPattern(Color.Yellow)
   .Paint
' Draws an arc:
   .LineWidth = 10.0
   .Arc(300, 300, 100.0, 45.0 * (Pi / 180.0), 180.0 * (Pi / 180.0))
   .Source = .ColorPattern(Color.Blue)    ' Sets the color of the drawing element:
   .Stroke   
' Draws a full colored arc:
   .LineWidth = 10.0
   .ArcNegative(400, 300, 100.0, 45.0 * (Pi / 180.0), 180.0 * (Pi / 180.0))
   .Source = .ColorPattern(Color.Orange)
   .Fill
' Writes a text:
   .Font.Size = 20
   .Font.Name = "URW Palladio L"
   .Source = .ColorPattern(Color.Red)
   .MoveTo(100, 200)
   .DrawText("Drawtext")
   .Fill
   .Source = .ColorPattern(Color.Green)
   .MoveTo(400, 300)
   .Font.Bold = True
   .Text("Text")
   .Fill
' Draws 10x10 filled squares:
   For x = 0 To 9
     For y = 0 To 9
       .Rectangle(200 + x * 10.0, 500 + y * 10.0, 5, 5)
     Next
   Next
  .Source = .ColorPattern(Color.Violet)
  .Fill   
' Two images are inserted:
  im = Image.Load("/usr/share/icons/breeze-dark/devices/64/battery.svg")
  im2 = Image.Load("/usr/share/icons/breeze-dark/devices/64/media-optical-video.svg") 
  im2 = im2.Stretch(im2.W * 2, im2.H * 2)      ' Doubles the size of the second image:
  .Source = Cairo.ImagePattern(im, 350, 600)
  .Paint            ' Sets the image to the PNG surface
  .Source = .ImagePattern(im2, 60, 400)
  .Paint            ' Sets the image to the PNG surface
' Finish the drawing:
  .End
 End With

' Save the surface contents as a PNG file
' (https://gambaswiki.org/wiki/comp/gb.cairo/cairosurface/save):
 png.Save("/tmp/file.png")
 
 End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Printing to a Zebra LAN Printer

Post by cogier »

Do you have any examples of how you used the gb.cairo?
vuott's code is a good start. The code below is designed to create a PDF file with the words 'Hello world!' and saves it to the /tmp/ folder. The label size is 50 x 25mm (2" x 1")

'' Requires gb.cairo

Public Sub Form_Open()
  
  CreatePDF("Hello world!")
  
End

Public Sub CreatePDF(sText As String)
  
  Dim pdf As CairoPdfSurface
  
  pdf = New CairoPdfSurface("/tmp/myprint.pdf", 50.8, 25.4)
  
  With Cairo
    .Begin(pdf)
    .Source = Cairo.ColorPattern(Color.White)
    .Paint()
    .Font.Name = "Ubuntu"
    .Font.Size = 25
    .Source = Cairo.ColorPattern(Color.Black)
    .MoveTo(Centre(Cairo.TextExtents(sText).XAdvance), 40)
    .Text(sText)
    .Fill()
    .End
  End With
  
  pdf.Finish
  
End

Public Sub Centre(fPoints As Float) As Float
  
  Dim fWidth As Float = 50.8 / 25.4 * 72 
  Return (fWidth - fPoints) / 2
  
End

Could I use that to print multiple labels across the page?
Simply loop through
Shell "lp /tmp/myprint.pdf" Wait
as many time as necessary.
Post Reply