Search code examples
c++printingofstreamzebra-printers

Zebra-printer TTP 2030 does not work


I'm trying to print "Hello World" in a Zebra Printer TTP 2030.

std::ofstream of;

of.open("Zebra TTP 2030");
if (of.is_open())
{
  debug(std::string("open : ok"));

  of << ticket.generateCode(); // return std::string
                               // ^XA^FO50,50^ADN,10,10^FDHello World^FS^XZ
  of.flush();
  of.close();
}
else 
  debug(std::string("open : ko"));

In the console, "open : ok" is trace.

I'm on a Microsoft XP Pro (VM). I'm working on Visual Studio 2010. The printer is setup on the VM.

Does someone know why a ticket is not created?


Solution

  • The way to print stuff from the command line is with print. Print, TechNet

    So you can achieve what you are asking by invoking print from your application. E.g.

    #include<fstream>
    #include<string>
    #include<cstdlib>
    
    void print_to_file(string filename){
        std::ofstream printer(filename);
        printer<<"Hello";
    }
    
    //create file with contents to print
    int main(){
        std::string filename("print_this.tmp");
        print_to_file(filename);
        std::string command("print \\d:\\\\ServerName\\PrinterName ");
        std::system(command + filename);
    }
    

    As noted by the TechNet article, you have a few options for the printer name.