Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WritePrinter Fails to Print on Inkjet Printer

WritePrinter Fails to Print on Inkjet Printer

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
11 Posts 4 Posters 0 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.
  • S Offline
    S Offline
    sandford_j
    wrote on last edited by
    #1

    Hi, I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition. My application has no problem to print on a dot matrix printer. But, it has problem when trying to print on Inkjet printer. My application fails to select a font type, change the font size or condensed through printer Escape character (Epson). Could you please help? Thank you. Cheers, Sandford

    D L M 4 Replies Last reply
    0
    • S sandford_j

      Hi, I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition. My application has no problem to print on a dot matrix printer. But, it has problem when trying to print on Inkjet printer. My application fails to select a font type, change the font size or condensed through printer Escape character (Epson). Could you please help? Thank you. Cheers, Sandford

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      sandford_j wrote:

      My application fails to select a font type, change the font size or condensed...

      Do these features work on the dot matrix printer?

      sandford_j wrote:

      Could you please help?

      Without seeing any code? How would you propose we do this? What sort of error checking do you have in place? Have you eliminated all the code except that which is absolutely necessary to reproduce the problem?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      S 1 Reply Last reply
      0
      • S sandford_j

        Hi, I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition. My application has no problem to print on a dot matrix printer. But, it has problem when trying to print on Inkjet printer. My application fails to select a font type, change the font size or condensed through printer Escape character (Epson). Could you please help? Thank you. Cheers, Sandford

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        [Installing the Epson Universal Print Driver -Windows](https://files.support.epson.com/docid/cpd4/cpd41354/source/printers/source/printing\_software/windows\_fy13/tasks/installing\_printer\_universal.html)

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        S 1 Reply Last reply
        0
        • D David Crow

          sandford_j wrote:

          My application fails to select a font type, change the font size or condensed...

          Do these features work on the dot matrix printer?

          sandford_j wrote:

          Could you please help?

          Without seeing any code? How would you propose we do this? What sort of error checking do you have in place? Have you eliminated all the code except that which is absolutely necessary to reproduce the problem?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          S Offline
          S Offline
          sandford_j
          wrote on last edited by
          #4

          Hi David, Font selection, font size and condensed printing work with dot matrix printer that support Esc/P. Unpredictable problems occur when trying to print on Inkjet printers such as: 1. The printer ignores the font type, font size and condensed printing. 2. Both Epson WF-7611 and HP OfficeJet Pro do not accept "RAW" for the data type in "StartDocPrinter" parameter. Epson WF-7611 will only accept "Text", while HP OfficeJet Pro only accept "XPS_XPSS". This means I have to detect what printer to print before assigning the data type. 3. The Win32 Printing API says that calling "EndPagePrinter" will end the current page, but it doesn't work that way. Thank you. Sandford Please refer to the code below: BOOL testPrint (char dataToPrint []) { char pName [1024]; DWORD level, sizeof_pName; HANDLE hPrinter; DOC_INFO_1 DocInfo; DWORD dwJob; DWORD dwBytesToPrint, dwBytesPrinted; sizeof_pName = sizeof(pName); memset (pName, 0, sizeof(pName)); if (!GetDefaultPrinter(pName, &sizeof_pName)) { printf ("Fail to GetDefaultPrinter. "); return FALSE; } if(!OpenPrinter (pName, &hPrinter, NULL)) { printf ("Fail to OpenPrinter [%s]. ", pName); return FALSE; } level = 1; DocInfo.pDocName = "My Document"; DocInfo.pOutputFile = NULL; DocInfo.pDatatype = "TEXT"; if((dwJob = StartDocPrinter(hPrinter, level, (LPSTR)&DocInfo)) == 0) { ClosePrinter (hPrinter); printf ("Fail to StartDocPrinter [%s]. ", pName); return FALSE; } if(!StartPagePrinter (hPrinter)) { EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to StartPagePrinter [%s]. ", pName; return FALSE; } dwBytesToPrint = strlen(dataToPrint); if(!WritePrinter (hPrinter, dataToPrint, dwBytesToPrint, &dwBytesPrinted)) { EndPagePrinter (hPrinter); EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to WritePrinter [%s]. ", pName); return FALSE; } if(!EndPagePrinter (hPrinter)) { EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to EndPagePrinter [%s]. ", pName); return FALSE; } if(dwBytesPrinted != dwBytesToPrint) { printf ("Fail to print [%s] to [%s]. ", dataToPrint, pName); return FALSE; } if(!EndDocPrinter(hPrinter)) { ClosePrinter(hPrinter); printf ("Fail to EndDocPrinter [%s]. ", pName); return FALSE; } ClosePrinter(hPrinter); return TRUE; }

          D 1 Reply Last reply
          0
          • L Lost User

            [Installing the Epson Universal Print Driver -Windows](https://files.support.epson.com/docid/cpd4/cpd41354/source/printers/source/printing\_software/windows\_fy13/tasks/installing\_printer\_universal.html)

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

            S Offline
            S Offline
            sandford_j
            wrote on last edited by
            #5

            Hi Gerry, Thanks. I will try. Sandford

            1 Reply Last reply
            0
            • S sandford_j

              Hi David, Font selection, font size and condensed printing work with dot matrix printer that support Esc/P. Unpredictable problems occur when trying to print on Inkjet printers such as: 1. The printer ignores the font type, font size and condensed printing. 2. Both Epson WF-7611 and HP OfficeJet Pro do not accept "RAW" for the data type in "StartDocPrinter" parameter. Epson WF-7611 will only accept "Text", while HP OfficeJet Pro only accept "XPS_XPSS". This means I have to detect what printer to print before assigning the data type. 3. The Win32 Printing API says that calling "EndPagePrinter" will end the current page, but it doesn't work that way. Thank you. Sandford Please refer to the code below: BOOL testPrint (char dataToPrint []) { char pName [1024]; DWORD level, sizeof_pName; HANDLE hPrinter; DOC_INFO_1 DocInfo; DWORD dwJob; DWORD dwBytesToPrint, dwBytesPrinted; sizeof_pName = sizeof(pName); memset (pName, 0, sizeof(pName)); if (!GetDefaultPrinter(pName, &sizeof_pName)) { printf ("Fail to GetDefaultPrinter. "); return FALSE; } if(!OpenPrinter (pName, &hPrinter, NULL)) { printf ("Fail to OpenPrinter [%s]. ", pName); return FALSE; } level = 1; DocInfo.pDocName = "My Document"; DocInfo.pOutputFile = NULL; DocInfo.pDatatype = "TEXT"; if((dwJob = StartDocPrinter(hPrinter, level, (LPSTR)&DocInfo)) == 0) { ClosePrinter (hPrinter); printf ("Fail to StartDocPrinter [%s]. ", pName); return FALSE; } if(!StartPagePrinter (hPrinter)) { EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to StartPagePrinter [%s]. ", pName; return FALSE; } dwBytesToPrint = strlen(dataToPrint); if(!WritePrinter (hPrinter, dataToPrint, dwBytesToPrint, &dwBytesPrinted)) { EndPagePrinter (hPrinter); EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to WritePrinter [%s]. ", pName); return FALSE; } if(!EndPagePrinter (hPrinter)) { EndDocPrinter (hPrinter); ClosePrinter (hPrinter); printf ("Fail to EndPagePrinter [%s]. ", pName); return FALSE; } if(dwBytesPrinted != dwBytesToPrint) { printf ("Fail to print [%s] to [%s]. ", dataToPrint, pName); return FALSE; } if(!EndDocPrinter(hPrinter)) { ClosePrinter(hPrinter); printf ("Fail to EndDocPrinter [%s]. ", pName); return FALSE; } ClosePrinter(hPrinter); return TRUE; }

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              As Esc/P is an older technology only supported by a few printers, have you considered using PCL instead?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              S 1 Reply Last reply
              0
              • D David Crow

                As Esc/P is an older technology only supported by a few printers, have you considered using PCL instead?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                S Offline
                S Offline
                sandford_j
                wrote on last edited by
                #7

                I did try to use PCL6 but fail. I send the PCL command by calling WritePrinter API. I do not know if I need to call another Win32 Printing API to send the PCL command. The PCL command is arranged in an array of bytes. But, no response from the printer. Any code sample to send PCL command, please? Thank you. Sandford

                1 Reply Last reply
                0
                • S sandford_j

                  Hi, I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition. My application has no problem to print on a dot matrix printer. But, it has problem when trying to print on Inkjet printer. My application fails to select a font type, change the font size or condensed through printer Escape character (Epson). Could you please help? Thank you. Cheers, Sandford

                  M Offline
                  M Offline
                  mo1492
                  wrote on last edited by
                  #8

                  Just a suggestion if you get really desperate; If the printer has a hex dump mode feature you can enable it and print out exactly what's being sent to the printer. Another way is to set the printer driver to 'Print to File' and your job will print to a file. Then if you are familiar with the printer language, you can examine the data to see if something has been added or missing in the printer data stream. Good luck

                  S 1 Reply Last reply
                  0
                  • M mo1492

                    Just a suggestion if you get really desperate; If the printer has a hex dump mode feature you can enable it and print out exactly what's being sent to the printer. Another way is to set the printer driver to 'Print to File' and your job will print to a file. Then if you are familiar with the printer language, you can examine the data to see if something has been added or missing in the printer data stream. Good luck

                    S Offline
                    S Offline
                    sandford_j
                    wrote on last edited by
                    #9

                    Thanks. Sandford

                    1 Reply Last reply
                    0
                    • S sandford_j

                      Hi, I have a Win32 application written in C and compiled by MS Visual Studio 2017 Community Edition. My application has no problem to print on a dot matrix printer. But, it has problem when trying to print on Inkjet printer. My application fails to select a font type, change the font size or condensed through printer Escape character (Epson). Could you please help? Thank you. Cheers, Sandford

                      M Offline
                      M Offline
                      mo1492
                      wrote on last edited by
                      #10

                      I found some old code that I wrote some time ago but never tested. I did a quick test with it and found that when I printed to my hp laserjet that I was only getting 1/2 of the data. After a little investigating I found that i didn't adjust for unicode data so using "RAW" mode passing 2 * datasize to WritePrinter((void*)data, 2*datasize, &dwBytesWritten) seem to fix the problem. However, as I said, this code is not fully tested so don't know if this is a real fix or if it has anything to do with your problem. I have problem using "TEXT" mode also but don't feel like investigating. The documentation just says "size of the array". Doesn't mention anything about unicode. Test data _T("abcd") Sending a size of 4 resulted in "ab" printing out. Sending a size of 8 resulted in "abcd" printing out. Also, if your printer data escape sequence as nul values in it, you may have to adjust it for unicode; ie. double nul. _T("escN") + nul + nul Best regards.

                      S 1 Reply Last reply
                      0
                      • M mo1492

                        I found some old code that I wrote some time ago but never tested. I did a quick test with it and found that when I printed to my hp laserjet that I was only getting 1/2 of the data. After a little investigating I found that i didn't adjust for unicode data so using "RAW" mode passing 2 * datasize to WritePrinter((void*)data, 2*datasize, &dwBytesWritten) seem to fix the problem. However, as I said, this code is not fully tested so don't know if this is a real fix or if it has anything to do with your problem. I have problem using "TEXT" mode also but don't feel like investigating. The documentation just says "size of the array". Doesn't mention anything about unicode. Test data _T("abcd") Sending a size of 4 resulted in "ab" printing out. Sending a size of 8 resulted in "abcd" printing out. Also, if your printer data escape sequence as nul values in it, you may have to adjust it for unicode; ie. double nul. _T("escN") + nul + nul Best regards.

                        S Offline
                        S Offline
                        sandford_j
                        wrote on last edited by
                        #11

                        Noted. Thanks. Sandford

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups