0

I am currently printing on a Zebra printer, and it prints the label normally from ZPL, but if I add an image to the ZPL code, it does not print anything, I add the image from ZPL with the add image option, any solution? Thanks:)

Code without image:

^XA
^FX Third section with bar code.
^BY5,2,270
^FO100,250^BC^FD12345678^FS
^FX Fourth section (the two boxes on the bottom).
^FO60,600^GB700,200,3^FS
^CF0,40
^FO150,650^FDREFERENCIA:ASDFGHJK211 ^FS
^FO300,710^FDTALLA:32 ^FS
^XZ

With image:

^XA


^FX Third section with bar code.
^BY5,2,270
^FO100,250^BC^FD12345678^FS
^FX Fourth section (the two boxes on the bottom).
^FO60,600^GB700,200,3^FS
^CF0,40
^FO150,650^FDREFERENCIA:ASDFGHJK211 ^FS
^FO300,710^FDTALLA:32 ^FS
^XZ

I use a class RawPrinterHelper.

using System;
using System.Drawing.Printing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using static RawPrinterHelper;

namespace a
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = "^XA^FO50,50^XGc:a.GRF^FS^XZ ";
            PrintDialog pd = new PrintDialog();
            pd.PrinterSettings = new PrinterSettings();
            if (DialogResult.OK == pd.ShowDialog(this))
            {
                //CODIGO CORRECTO ABAJO
                //^ XA ^ FO ^ FO300,20 ^ C:2033.PNG Third section with bar code.^ BY5,2,270 ^ FO100,250 ^ BC ^ FD12345678 ^ FS ^ FX Fourth section(the two boxes on the bottom).^ FO60,600 ^ GB700,200,3 ^ FS ^ CF0,40 ^ FO150,650 ^ FDREFERENCIA:ASDFGHJK211 ^ FS ^ FO300,710 ^ FDTALLA:32 ^ FS ^ XZ
                //---------------------------------//Imagen
                //^ XA ^ FO20,20 ^ XGR:2033.PNG ^ XZ
                RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
            }
        }

        public static bool SendTextFileToPrinter(string szFileName, string printerName)
        {
            var sb = new StringBuilder();

            using (var sr = new StreamReader(szFileName, Encoding.Default))
            {
                while (!sr.EndOfStream)
                {
                    sb.AppendLine(sr.ReadLine());
                }
            }

            return RawPrinterHelper.SendStringToPrinter(printerName, sb.ToString());
        }
  • 1
    You have posted far too much code for us to help you with. Please trim it down to the absolute-minimum required to reproduce the issue. – Dai Jul 08 '22 at 21:27
  • @Dai Sorry, but much of the code you see is just the code that is generated when you add an image. – Andres Martinez Jul 08 '22 at 21:34
  • What's wrong with the placement of `^XA` and `^XZ` @jdweng? – GSerg Jul 08 '22 at 22:08
  • 1
    Nothing, XA and XZ go at the end and beginning of the code respectively, so I don't think their locations are wrong. – Andres Martinez Jul 08 '22 at 22:12
  • That's a rather big picture that is a bit cropped and positioned over the barcode. Is that what you intended? – GSerg Jul 08 '22 at 22:20
  • Yes, although I already shrunk the image using Paint, and the result is still the same, and yes that was my intention(the image is not located in the correct coordinates but yes, it should go above the barcode, accommodated or not the result is the same). – Andres Martinez Jul 08 '22 at 22:24
  • That command uses [the](https://stackoverflow.com/q/68627676/11683) "Alternative Data Compression Scheme for ~DG and ~DB Commands". My manual does not cover it and I'm not sure which firmware versions support it. In the thing that encodes the picture, can you specify a different encoding, e.g. ZB64? – GSerg Jul 08 '22 at 23:06
  • If the picture is going to be always the same, would you consider to store the image on the printer memory and just recall it in the ZPL code of the label? This could solve your problem – ZRep Jul 09 '22 at 14:00
  • @ZRep Yes, of course, I'm willing to try anything as long as it works. Do you have any link or page where I can check how to do that? – Andres Martinez Jul 09 '22 at 17:02
  • Have a look here https://supportcommunity.zebra.com/s/article/Zebra-Setup-Utilities--Downloading-Graphics-to-a-Printer?language=en_US and here you can check how to recall the graphic https://supportcommunity.zebra.com/s/article/Convert-Download-and-Print-Graphics-to-a-ZPL-compatible-Zebra-Printer?language=en_US using the XG ZPL command – ZRep Jul 10 '22 at 10:31
  • @ZRep I tried, but it still doesn't print images, do you think the problem could be in the code I use, I will edit the question and put it. – Andres Martinez Jul 11 '22 at 20:25
  • Did you save the image as monochrome bitmap? – Delphi Coder Jul 12 '22 at 04:58
  • You can use http://labelary.com/viewer.html for playing around with ZPL. – Delphi Coder Jul 12 '22 at 04:58
  • @DelphiCoder yes, the Zpl is fine, the problem is that adding an image prints blank. – Andres Martinez Jul 12 '22 at 16:35
  • Can you test with a smaller image? Maybe you hit some image size limitation... – Delphi Coder Jul 12 '22 at 18:35
  • I just tried with a very, very small image and it worked, thank you very much. – Andres Martinez Jul 12 '22 at 18:49

0 Answers0