问题
I would like send ZPL instructions to a Zebra printer (GK420t for now). I'm printing 50mm x 20mm labels. I would like a logo (small ~ 5mm x 5mm image) to be printed on the upper left corner of the label.
I would like to know the steps I should follow to do this.
I have been reading and trying a few things from the ZPL manual but I don't really understand how it works and couldn't find a working example.
It looks like I have to "load" the image into the printer first (in a so-called "storage area"/DRAM?) and then print it.
The .GRF
file extension is mentioned many times in the manual.
I couldn't find the tool to convert a .PNG or .BMP image into a .GRF file.
I read that a .GRF file is an ASCII HEX representation of a graphic image... but it didn't help me do the work.
I could print the logo on the labels using the "Zebra Setup Utilities", by "Downloading Fonts and Graphics", choosing any available .MMF file, adding a .BMP picture, downloading it [to the printer] and printing a test page. But until now, I couldn't do it using ZPL instructions.
I am also wondering what are the best dimensions I should use given the fact that I need a small image ~5mm x 5mm to be printed on the labels. The image I printed is a 40px x 40px image. Also, if I have to make a .GRF file from an original image what should be the type of this file (.BMP, .PNG, .JPG)?
Can you advise me how to proceed?
回答1:
It sounds like you have some existing ZPL code, and all you want to do is add an image to it.
If that's the case, the easiest solution is probably to go to the Labelary online ZPL viewer, paste your ZPL into the viewer, click "Add image", and upload the image that you want to add to the ZPL.
This should modify your ZPL by adding the image ZPL commands that you need, and you can then tweak the position, etc.
回答2:
Here is another option: I created my own image to .GRF converter in python. Feel free to use it.
https://github.com/JoshMayberry/Utilities/blob/master/image2grf.py
from PIL import Image
import re
import numpy as np
def image2grf(filePath, length = None, width = None):
#Open the image
image = Image.open(filePath)
image = image.convert("1") #Ensure that it is black and white image
#Resize image to desired size
if ((length != None) and (width != None)):
size = (length, width)
image.thumbnail(size, Image.ANTIALIAS)
#Convert image to binary array
bitmap = np.asarray(image, dtype = 'int')
bitmap = np.asarray(bitmap, dtype = 'str').tolist()
#Convert binary array to binary string
binaryString = ""
for row in bitmap:
#Join the row to the string
row = "".join(row)
#Make each pixel square (for some reason it is rectangular)
binaryString += row
binaryString += row
binaryString += row
binaryString += row
#Convert binary string to hex string
hexString = re.sub("0","F",binaryString)
hexString = re.sub("1","0",hexString)
#Calculate bytes per row and total bytes
bytesPerRow = len(bitmap[0]) / 2
totalBytes = bytesPerRow * len(bitmap) * 4 #0.5 for each line piece in a line
#Compose data
data = "~DGimage," + str(totalBytes) + "," + str(bytesPerRow) + "," + hexString
#Save image
fileHandle = open(r"labelPicture.grf", "w")
fileHandle.write(data)
fileHandle.close()
if __name__ == '__main__':
image2grf(r"test.bmp")
回答3:
Just install ZebraDesigner, create a blank label, insert a image object to the template and add the required logo image.
Print to File this label (a *.prn file) and open the recently created file with Notepad++ (MS Notepad will ruin the data if opened and saved with). Find a huge string of seemingly random characters, and there is your image's data. Careful not to lose any of those characters, including the control ones, as the whole string is a textual representation of your image (as it would be if it were base64).
Tip0: Always have your ZPLII Programmer's Guide at hand, you'll need/want to check if ZebraDesigner sent the image to memory or directly to the printer buffer.
Tip1: Before adding the logo to the label and get the text, prepare the image making it greyscale (remember to check the printer's dithering configuration!) or, in my case, plain black and white (best result IMHO). The image can be colored, the ZebraDesigner will make it work for the printer converting the image to greyscale before conversion to commands and text.
回答4:
I created a PHP script to convert PNG images to .GRF similar to Josh Mayberry's image2grf.py: https://gist.github.com/thomascube/9651d6fa916124a9c52cb0d4262f2c3f
It uses PHP's GD image function and therefore can work with all the file formats GD can open. With small modifications, the Imagick extension could be used but performance seems to be better with GD.
回答5:
Try codeproject's sharpzebra project. The test program that is part of project prints a graphic and I know this works at least it did on a ZM400
回答6:
go to Object ==> Picture and your curser will change to something else.. when it changed go and click on the working area and a dialog box iwll apear... so on there select the image so you can see the image whant you wanna print on the printer i am using GT800 so for me i did like that hope this will helps you
来源:https://stackoverflow.com/questions/29253453/how-to-print-a-logo-on-labels-using-a-zebra-printer-and-sending-zpl-instructions