Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printing ZPL text to Zebra printer with Qprinter adds unwanted spaces
Forum Updated to NodeBB v4.3 + New Features

Printing ZPL text to Zebra printer with Qprinter adds unwanted spaces

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 5.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marlloz
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cccm62
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DocZorg
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violette
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violette
            wrote on last edited by
            #5

            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");
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved