We have to develop a SW to print labels using a Zebra LP2824 printer,
which conects to the PC by USB. How may I send the ZPL commands to
print what I am supposed to? Is it possible to use fonts like Arial,
Times New Roman, etc?
Thx in advance.
> We have to develop a SW to print labels using a Zebra
> LP2824 printer, which conects to the PC by USB.
I don't use Label Printers myself but you should be able to use your
Zebra either by printing stuff to it in the normal way using the VB
Printer Object or alternatively by sending data (text, control codes,
etc, etc) directly to the printer. The former method probably severely
limits what you can do with Label Printers, but is very easy. The
latter method enables you to do anything that the printer is capable
of, but it requires an in depth knowledge of the various control codes
and/or language that your printer understands. I would imagine that
printers such as a Zebra Label Printer would come with various user
and programming manuals. Do you have these? If not then you should be
able to download them in pdf format from the Zebra website. I've just
had a quick look and I can see a few different manuals available at:
http://www.zebra.com/id/zebra/na/en/index/resource_library/manuals.html
> Is it possible to use fonts like Arial,
> Times New Roman, etc?
As I've said, I've never actually used a Label Printer but I imagine
that if your requirements are limited and if you use the VB Printer
Object then Windows will allow you to use such fonts and will
rasterise them for you and send them to the printer as graphics.
However, for most real world tasks on a Label Printer I imagine you
will almost certainly need to address the Zebra directly instead of
using the VB Printer Object, in which case I'm sure there will be
details in one or other of the available manuals explaining how to use
such fonts. I've just downloaded and had a very quick look at some of
the Zebra LP2824 manuals and it would appear that it has five standard
built in fonts, all of which are mono spaced. It does however have the
capability of downloading TrueType fonts into its memory and there is
some ZebraDesigner Font Downloader software which I imagine will take
all the hard work out of that task for you and make it very easy. Once
you've uploaded the required TrueType fonts (Arial, Times New Roman or
whatever) to your Zebra printer then it should be able to use them and
print them very quickly. I imagine that you already have the
ZebraDesigner Font Downloader software, but if not then you should be
able to obtain it from Zebra, perhaps as a free download. I'm sure
there will be Zebra control codes that also enable you to perform such
a task anyway, but the Zebra software will obviously be the easier
option.
> How may I send the ZPL commands to print
> what I am supposed to?
You won't be able to use the standard VB Printer Object to do stuff
like that so you will need to bypass the standard Windows drivers and
instead send raw data direct to your printer, as in the following
example which can send raw data to any connected printer, including
USB connected printers. I've used a String in the example to contain
the data sent to the printer and you'll be able to include any
necessary control codes etc in the string, but you can easily amend it
to use a Byte Array instead if you prefer. As I've already said, I've
never actually used a Zebra printer or any other Label Printer and so
I don't offhand know what control codes it accepts or whether it
requires any initialisation string, so in the example I've just sent
some text followed by a standard FormFeed character. I don't know
whether the FormFeed character will work with your Zebra, or if it
will print the text in its default font without any other
initialisation codes, but if any part of it does not work then you
will be able to send it the appropriate Zebra Escape sequence instead
(either by building the required code bytes into a VB string or by
using a Byte array).
I'm afraid all this is mostly guesswork at the moment because I don't
have a suitable printer on which to try my code but it'll give you a
start. In fact I answered your question simply because I saw the word
"Zebra" in it and I remember quite some time ago answering some
questions about a Zebra printer (questions about page size or
printable area or precise positioning of printed elements or something
like that as far as I recall?). It was either on this newsgroup or on
the microsoft.public.vb.general.discussion group. I don't remember the
details now or whether there was anything in it that may also be of
interest to you, but it might be worth checking the archives (I can't
seem to see it at the moment myself). Anyway, here's the "direct to
printer" sample code. It should (hopefully) print "Hello World" and
eject the label on your Zebra, although you will be able to use the
same code to send anything you wish, including the various control
codes.
The code as it stands simply sends the data to whatever happens to
currently be your Windows default printer, so you will need to set the
Zebra as your default printer to try it. It will be very easy to amend
it though (if you wish to do so) in such a way that the code picks out
the Zebra whether it is your default printer or not. Paste the code
into a new VB project (one Form with a Command Button on it) and run
the project and click the button. Let me know if it works.
By the way, I use VB6 myself and I notice you are using VB5 but I
think the code should still work okay in VB5 because I haven't used
any VB6 specific stuff in it.
Mike
Option Explicit
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" _
Alias "StartDocPrinterA" (ByVal hPrinter As Long, _
ByVal Level As Long, pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long, pBuf As Any, _
ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Sub Command1_Click()
Dim myPrinter As Long, myDoc As Long, MyDocInfo As DOCINFO
Dim sWrite As String, charsWritten As Long, retVal As Long
retVal = OpenPrinter(Printer.DeviceName, myPrinter, 0)
If retVal = 0 Then
MsgBox "Printer Not found"
Exit Sub
End If
MyDocInfo.pDocName = "Any Name"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
myDoc = StartDocPrinter(myPrinter, 1, MyDocInfo)
Call StartPagePrinter(myPrinter)
'
' send whatever you wish here
sWrite = "Hello World." & vbCrLf
retVal = WritePrinter(myPrinter, ByVal sWrite, _
Len(sWrite), charsWritten)
'
sWrite = vbFormFeed
retVal = WritePrinter(myPrinter, ByVal sWrite, _
Len(sWrite), charsWritten)
retVal = EndPagePrinter(myPrinter)
retVal = EndDocPrinter(myPrinter)
retVal = ClosePrinter(myPrinter)
End Sub
Pepito, please regard this as utterly unreliable, just a guess. I don't
know what ZPL means. It really needs an expert, not me :-) I have an HP
printer, this works for me.
Option Explicit
Private Sub Form_Load()
Dim i As Long
For i = 0 To Printers.Count - 1
If InStr(Printers(i).DeviceName, "hp") Then
Exit For
End If
Next i
Set Printer = Printers(i)
Printer.FontSize = 18
Printer.Print "ABC*"
Printer.EndDoc
End Sub
Regards
> Pepito <snip> I have a HP printer, this works for me.
> <snip>
> Printer.FontSize = 18
> Printer.Print "ABC*"
> Printer.EndDoc
Hi Martin. Nice to see you are still out and about. How's it going up
there in Trump Towers these days :-)
Your suggested code which uses the installed Windows printer drivers
for the Zebra (via the VB Printer Object) will almost certainly work
with the Zebra in much the same way as they work with your HP, and so
probably will many of the other various Printer Object methods (True
Type font selection, printer's bar code fonts, font size, text output,
line graphics, etc). In my own response I sort of skipped over those
functions (with just a brief mention of them) and I concentrated on
giving the OP code to allow him to use the alternative method of
bypassing the Zebra Windows printer driver and instead sending raw
data directly to the printer, since this will allow him to send it the
ZPL commands that he specifically asked for.
> I don't know what ZPL means <snip>
The ZPL to which the OP is referring is as far as I know is a small
proprietry language specifically designed for controlling Zebra label
printers. I've downloaded the printer manuals from the Zebra web page,
just out of interest, and they are for something called for EPL and
EPL2 (after a bit of Googling it appears that Zebra was at one point
in time called Eltron, hence the E instead of the Z). It's not really
a programming language, but more of a straightforward printer control
set, something similar to the Epson EscP and NEC and various other
printer control languages that became industry standards when the old
fashioned impact dot matrix printers were in common use. Essentially
you control the printer by sending it various control characters and
codes (what we used to call Escape sequences in the old days!). In
this way you can gain complete control over the printer and make it do
things that it would not be able to do using the VB Printer Object
methods. I don't have any experience of controlling Zebra printers or
other label printers of course, having never used one, but I imagine
it will be similar in many ways to the way that I used to drive my old
Citizen dot matrix printer about twenty five years ago!
Mike