[python-win32] win32 printer

Richard Peeters r.peeters at telenet.be
Tue Nov 28 12:19:11 EST 2017


 Hello,
I'm new to Python and this list.
> I installed pypiwin32 ,  
and demo runs without errors.... but nothing is printing. I checked and 
> nothing in cue
> Os is windows7.
> BTW is there a simple method to just print text (as lprint in basic)?

> tks Richard

> code:
> ----------------------------------
> #printer
> import os, sys
> import win32print
> printer_name = win32print.GetDefaultPrinter ()
> print(printer_name)
> #
> # raw_data could equally be raw PCL/PS read from
> #  some print-to-file operation
> #
> if sys.version_info >= (3,):
>   raw_data = bytes ("This is a test", "utf-8")
> else:
>   raw_data = "This is a test"
> 
> hPrinter = win32print.OpenPrinter (printer_name)
> print(hPrinter)
> try:
>   hJob = win32print.StartDocPrinter (hPrinter, 1, ("test of raw data", 
> None, "RAW"))
>   try:
>     win32print.StartPagePrinter (hPrinter)
>     win32print.WritePrinter (hPrinter, raw_data)
>     win32print.EndPagePrinter (hPrinter)
>   finally:
>     win32print.EndDocPrinter (hPrinter)
> finally:
>   win32print.ClosePrinter (hPrinter)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20171128/ecbde4e3/attachment.html>


More information about the python-win32 mailing list