Cannot print using OpenPrinterW function

yangjia 41 Reputation points

system: windows10 pro
the printer: hp laser108a
I want to programmatically control my printer to print a txt or pdf document, Then I step by step according to the msdn above description, using OpenPrinter,StartDocPrinter,StartPagePrinter,WritePrinter,EndPagePrinter,EndDocPrinter,ClosePrinter writing It's my program,But the printer didn't print the txt file I wanted.After I selected the advanced property "Keep printed documents" of the printer, I found that the task existed in the list, and the state was printed, but the actual result was that the printer did not print, please ask which step was wrong, thank you!

Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
611 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alan Morris 1,041 Reputation points

    What does Windows say is happening?

    Enable the PrintService/ Operational events

    Open Event Viewer
    Applications and services

    The Operational events are not enabled by default so turn on this event level and execute your code again.

    One other point, does the printer support the text datatype? It absolutely does not support PDF as a datatype.

    If you call the driver, then the driver should be converting the text or PDF into PCL which the printer supports.

    0 comments No comments