Prepare a ZPL command for printing the mono chrome bitmap image

siva Rapolu picture siva Rapolu · Jul 22, 2013 · Viewed 8.2k times · Source

I have a problem in preparing the ZPL command for printing the bitmap image on Zebra RZ400 300 dpi.

I have folling code snippet and i dont understand where i am extacly making a mistake.

var bitmapImagePath = @"C:\Sample.bmp";

//Gets the size of the bitmap file
 long bitmapDataFileSize = new FileInfo(bitmapImageFilePath).Length;

byte[] bitmapData = System.IO.File.ReadAllBytes(bitmapImageFilePath);
string hexadecmimalString = BitConverter.toString(bitmapData).replace("-", string.empty);

 double widthInBytes = Math.Ceiling(bitmapDataWidth / 8.0);

string str = "";
            return str = "^XA^FO100,100^GFA," + //At Postion 100, 100
                bitmapDataSize.ToString() + "," +     // Total bytes of data to be placed
                bitmapDataSize.ToString() + "," +     // Total bytes of data to be placed, repeats as per API
                widthInBytes + "," + //
                hexadecmimalString + "^XZ";

Can you please suggest me where its going wrong? I could able to print with Multiplat form SDK API, but i am intrested only in ^GFA or ^GFB command which suits my requrirement.

Can any please suggest me to prepare the ^GF command that prints the any given image.

Answer

Daniel Lane picture Daniel Lane · Jul 22, 2013

https://stackoverflow.com/questions/7083180/print-bmp-with-zpl?rq=1

That should do the trick for you. As you're a new member I highly recommend you use the search feature.

Also this line:

var bitmapImagePath = :C:\\Sample.bmp";

should be

var bitmapImagePath = @"C:\Sample.bmp";

You potentially have two options.

If you don't need to use ZPLII, you can install the printer using the Zebra drivers. This will allow you to use the Zebra printer as you would a regular desktop printer. You can then build your label using standard .Net functions for printing, and send the document to the printer as you would a regular document programmatically.

If this isn't an option, you'll need to create a monochrome bitmap, I've never done that myself. However you could use img2grf to convert if you don't feel like writing your converter. You'll need to convert that library into a .Net assembly, which can easily be achieved by using IKVM. For instructions on how to use IKVM simply visit HtmlUnit Conversion with IKVM and follow the instructions under the "Converting HtmlUnit to .NET" section, it's the same process to convert img2grf.