On 7 Sep, 09:13, Pepito Grillo <bar...@gmail.com> wrote:
> 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
|