微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试在Windows的ESC / POS打印机中以加粗,双倍高和双倍宽度的文本进行打印,但此方法不起作用

如何解决尝试在Windows的ESC / POS打印机中以加粗,双倍高和双倍宽度的文本进行打印,但此方法不起作用

我已经通过Windows计算机上的USB端口安装了ESC / POS热敏打印机,并且尝试使用粗体,双倍高和双倍宽度的文本进行打印,但是它不起作用,我尝试使用WinAPI进行打印。 spooler cuz这是一台USB热敏打印机,我尝试了以下代码,但该打印机无法正常工作,无法正常打印文本大小

#include <windows.h>
#include <string>
#include <vector>
#include <codecvt>
#include <iostream>

      const char * posPrintername = "XP-58"; //seting printer
      LPTSTR szPrinterName;//declare wide size printer anme

      LPBYTE lpData,lpData2;//declare varaiable to print

      DWORD dwCount,dwCount2;//decalre length of print contents
      HANDLE     hPrinter; 
      DOC_INFO_1 DocInfo;
      DWORD      dwJob;
      DWORD      dwBytesWritten;

       //convert the printer name to the wide characters
        wchar_t * posPrinternamew = new wchar_t[strlen(posPrintername) + 1];
        mbstowcs_s(NULL,posPrinternamew,strlen(posPrintername) + 1,posPrintername,strlen(posPrintername));

      //pos58 instructions
      char initialstr[8] = "\x0D\x1B\x40\x0A";

      char bolderstr[2] = "\x08";

      char doubleheightstr[2] = "\x10";

      char  doublewidthstr[2] = "\x20";

      char  resetstr[2] = "\x00";
      //print test contents
      std::string printcontents = "hello world\n ";

      lpData = (LPBYTE)printcontents.c_str();
        dwCount = strlen(printcontents.c_str());

    // Need a handle to the printer.  
    
      szPrinterName = posPrinternamew;
     if (!OpenPrinter(szPrinterName,&hPrinter,NULL))
     {

        return -1;
     }

     // Fill in the structure with info about this "document."   
      DocInfo.pDocName = TEXT("My Document");
      DocInfo.pOutputFile = NULL;
     DocInfo.pDatatype = TEXT("RAW");
      // Inform the spooler the document is beginning.   
     if ((dwJob = StartDocPrinter(hPrinter,1,(LPBYTE)&DocInfo)) == 0)
    {

       ClosePrinter(hPrinter);
       return -2;
     }
     
     // Start a page.   
     if (!StartPagePrinter(hPrinter))
    {

         EndDocPrinter(hPrinter);
         ClosePrinter(hPrinter);
         return -3;
    }
    // Send the data to the printer.  tried to initial the printer 
    if (!WritePrinter(hPrinter,initialstr,(DWORD)4L,&dwBytesWritten))
    {

       EndPagePrinter(hPrinter);
       EndDocPrinter(hPrinter);
       ClosePrinter(hPrinter);
       return -4;
     }

     // Send the data to the printer.   tried to set the bolder text
    if (!WritePrinter(hPrinter,bolderstr,(DWORD)3L,&dwBytesWritten))
    {

        EndPagePrinter(hPrinter);
        EndDocPrinter(hPrinter);
        ClosePrinter(hPrinter);
        return -4;
     }

      // Send the data to the printer.   tried to print  with bolder text
     if (!WritePrinter(hPrinter,lpData,dwCount,&dwBytesWritten))
    {

        EndPagePrinter(hPrinter);
        EndDocPrinter(hPrinter);
        ClosePrinter(hPrinter);
        return -4;
     }

    //tried to set double height text
    if (!WritePrinter(hPrinter,doubleheightstr,&dwBytesWritten))
    {

      EndPagePrinter(hPrinter);
      EndDocPrinter(hPrinter);
      ClosePrinter(hPrinter);
      return -4;
    }

     // Send the data to the printer.   //tried to print with double height text 
    if (!WritePrinter(hPrinter,&dwBytesWritten))
   {

       EndPagePrinter(hPrinter);
       EndDocPrinter(hPrinter);
       ClosePrinter(hPrinter);
       return -4;
    }

  //tried to set double width text 
    if (!WritePrinter(hPrinter,doublewidthstr,&dwBytesWritten))
    {

        EndPagePrinter(hPrinter);
        EndDocPrinter(hPrinter);
        ClosePrinter(hPrinter);
        return -4;
     }

     // Send the data to the printer. //tried to print with double width text   
     if (!WritePrinter(hPrinter,&dwBytesWritten))
     {

         EndPagePrinter(hPrinter);
         EndDocPrinter(hPrinter);
         ClosePrinter(hPrinter);
         return -4;
      }

    //tried to reset the printer 
      if (!WritePrinter(hPrinter,resetstr,&dwBytesWritten))
      {

         EndPagePrinter(hPrinter);
         EndDocPrinter(hPrinter);
         ClosePrinter(hPrinter);
         return -4;
      }
      // End the page.   
     if (!EndPagePrinter(hPrinter))
     {

        EndDocPrinter(hPrinter);
        ClosePrinter(hPrinter);
        return -5;
      }
      // Inform the spooler that the document is ending.   
    if (!EndDocPrinter(hPrinter))
    {

       ClosePrinter(hPrinter);
       return -6;
    }
   // Tidy up the printer handle.   
   ClosePrinter(hPrinter);
   // Check to see if correct number of bytes were written.   
   if(dwBytesWritten != dwCount)
   {

         return -7;
    }
    return 0;

知道我做错了什么吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。