Important: Please read the Qt Code of Conduct -

Printing ZPL text to Zebra printer with Qprinter adds unwanted spaces

  • Hello all,

    I have been trying to print labels with a Zebra printer using QPrinter and a "Generic / Text Only" driver on USB001 local port in Windows 7 64bits with Qt 4.8.5.

    Tried doing it like these using the example ZPL command "prn":

    QPrinter printer(QPrinterInfo::defaultPrinter()); //the default printer is "Generic / Text Only"

    // With QTextDocument
    QTextDocument doc(prn);

    //With QPainter
    QPainter painter(&printer);

    Strangely Qt seems to add TAB spaces after letter "I" and " " (space), as far as I have tested.

    It prints:

    ABC [long space] DEFGHI [long space] JKLMNOPQRSTUVWXYZ

    When it should print like this :

    (tested printing from Notepad and printing to as PDF)

    Does any one knows what could be happening?


  • Hi,

    I have the same error, did you manage to resolve it?

    • Printing From ZebraDesigner : OK

    • Printing the .prn content from notepad : OK
      (print on RAW "Generic / Text Only" printer)

    • Printing the .prn content from Qt : SAME ERROR
      => adds spaces (or TABS)

    Thx, Cedric

  • I know it's been a long time, but I'm running into exactly the same problem, what solution did you come up with?
    Thanks for your time.

  • Hi guys,
    I also have the same problem.
    Printing is fine from notepad but not from qt with the exact same string.
    It adds spaces after spaces, ':', '-', '/'...
    Any solution found since then ??

  • Hi again,

    I found a solution for those who may be interested:

    Actually some special characters have a meaning for ZPL, but it is possible to replace them by there hexadecimal value preceded by '_'. Like this a '~' can be replaced by '_7e'...
    Check the ^FH in the ZPL manual.

    At my side I did something like this:

        QString escapedText(textField.text);
        QList<QChar> specialCharacters = QList<QChar>() << '~' << ' ' << ':' << ';' << '.' << '-' << '/' << '\\' << 'I' << '!' << '?' <<
                                                           '"' << '#' << '+' << '*' << '%' << '^' << '>' << '<';
        foreach (QChar ch, specialCharacters)
            escapedText = escapedText.replace(QString(ch), "_" % QString::number(ch.unicode(), 16));
        buildString.append("^FH^FD" % escapedText % "^FS\n");

Log in to reply