[Python] Python : win32print - data does not leave the print queue

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    Below is a small code in Python where I am trying to send a text to a specific printer and the printout is stuck in the printer queue.

    Can anyone tell me if there is anything else I need to add to the code?

    Note: The printer is on the network and working perfectly.

    I'm using Windows 11 and my Python version is Python 3.12.3

    import win32print

    v_printer_handle = win32print.OpenPrinter( "Brother DCP-L5652DN Printer" )

    v_job_name = "My Job"
    v_file_to_print = None
    v_data_type = "RAW"

    v_DocInfo = ( v_job_name, v_file_to_print, v_data_type )

    win32print.StartDocPrinter( v_printer_handle, 1, v_DocInfo )

    win32print.StartPagePrinter( v_printer_handle )

    raw_data = bytes( "This is a test printing python !", "utf-8" )

    v_bytes = win32print.WritePrinter( v_printer_handle, raw_data )

    print( "Bytes Sent: ", v_bytes )

    win32print.EndPagePrinter( v_printer_handle )

    win32print.EndDocPrinter( v_printer_handle )

    win32print.ClosePrinter( v_printer_handle )


    [​IMG]

    Appreciate any help
    Thanks

    I've already tried other functions like os.start and shellexecute without success! I have two needs, send any text or any file to a specific printer!

    Continue reading...

Compartilhe esta Página