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":

    @QString prn("^XA^FO121,41^A0N,19,15^FDABC DEFGHIJKLMNOPQRSTUVWXYZ^FS^XZ");
    QPrinter printer(QPrinterInfo::defaultPrinter()); //the default printer is "Generic / Text Only"

    // With QTextDocument
    QTextDocument doc(prn);
    doc.print(&printer);

    //With QPainter
    QPainter painter(&printer);
    painter.drawText(0,0,prn);
    printer.newPage();@

    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 :

    ABC DEFGHIJKLMNOPQRSTUVWXYZ
    (tested printing from Notepad and printing to as PDF)

    Does any one knows what could be happening?

    Thanks.



  • 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 ??
    Thanks,
    Violette



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.