1

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.

siva Rapolu
  • 409
  • 1
  • 8
  • 20
  • 1
    Are you just attempting to print a bitmap onto a label, or are you trying to do something more advanced than that? – Daniel Lane Jul 22 '13 at 12:33
  • You don't show where you got `ZPLImageDataString` and you never show what happens to `hexadecmimalString` – Scott Chamberlain Jul 22 '13 at 12:36
  • Hi Termin, I am trying to print a bitmap onto a lable. I could able to do it through multiplatform SDK provided by the Zebra. The reason i am looking for ^GF command is, i have few other elementes like barcode and other images to be printed on the same label, i would like to prepare the ZPL command and send all the commands at a time while printing. – siva Rapolu Jul 22 '13 at 13:21
  • Hi Scott, I am really sorry for misplacing the variable names. I corrected it now. Sorry for wasting your time on correcting the things. – siva Rapolu Jul 22 '13 at 13:21

1 Answers1

1

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.

Community
  • 1
  • 1
Daniel Lane
  • 2,575
  • 2
  • 18
  • 33
  • 1
    HI Termin, Syntax wise yes its a mistake. I posted the wrong systax but Visual studio doesnt allow me to do so :-), i have been through that post earlier, only GRF format files can be used for ^XGR command. To convert any image (BMP or PNG) to GRF, i need to use Zebra Net Bridge converter, which i dont want to do it manually. I want to pass the image to function, that function needs to return the proper ZPL command. I would like to use the ^GF command with options A (Ascii data) or B (binary data) as inputs. Can you please help me in doing so. – siva Rapolu Jul 22 '13 at 13:27
  • @siva, if you don't want to use Zebra Net Bridge converter, install the Zebra drivers and use the standard `System.Drawing.Printing.PrintDocument` printing. This is much easier to use, and will work on all Windows printers, not just Zebra printers. – Dour High Arch Jul 22 '13 at 19:53
  • Hi Dour, Unfortunately i cant use this API, because i am using the label printer, and on the label, including my image, i have few other widgets i say like barcode and some other text which were in form of ZPL commands. Its a limitation from my side like i have to prepare a ZPL command for this as well that fits to my legecy code. If you look at my above code, i am not fetching exact hexadecimal string probably. PrintDocument is really intresting probaly i need to consider for my future modules. Thankful to your suggestions and please advice for my code mentioned above. – siva Rapolu Jul 23 '13 at 06:43
  • Hi CapTec, Thankyou for providing img2grf, which was helped me to modify some code changes in my code. With that i could able to generate the grf image but i am ending up in prining the blurred image, which will not at all comparable with original image. Is this the problem with dirver settings or preferences? I am using Zebra RZ400 300dpi printer. – siva Rapolu Jul 23 '13 at 09:58
  • It's impossible for me to tell without seeing your setup. I'd recommend making sure that you've configured the printer correctly using the Zebra Setup Utility. It could be img2grf that's the issue. The issue could be any number of variables. It won't be your driver settings. It's most likely a scaling issue with your bitmap if it looks blurred. – Daniel Lane Jul 23 '13 at 13:33