Cannot print using OpenPrinterW function

yangjia 41 Reputation points
2022-10-24T09:06:35.69+00:00

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!
253457-image.png

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
675 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alan Morris 1,161 Reputation points
    2022-11-03T13:35:05.943+00:00

    What does Windows say is happening?

    Enable the PrintService/ Operational events

    Open Event Viewer
    Applications and services
    Microsoft
    Windows
    PrintService

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.