How to print via python on windows

L

loial

What is the easiest way to send a text file to a networked printer
from a python script running on windows?
 
R

rantingrick



Hello Tim,

Thanks for posting this wonderful win32 info at your site. I have used
it quite extensively in the past and would like to know if you are
interested in adding a bit more to the code to this simplistic
example...

import win32print
printer_name = win32print.GetDefaultPrinter ()
#
# raw_data could equally be raw PCL/PS read from
# some print-to-file operation
#
raw_data = "This is a test"

hPrinter = win32print.OpenPrinter (printer_name)
try:
hJob = win32print.StartDocPrinter (hPrinter, 1, ("test of raw data",
None, "RAW"))
try:
win32print.WritePrinter (hPrinter, raw_data)
finally:
win32print.EndDocPrinter (hPrinter)
finally:
win32print.ClosePrinter (hPrinter)

.... It would be nice to include some code to paginate the text. Also
what seems to be missing from the Python world is some info on
configuring a printer programically. MSDN is not much help to anybody
and really nothing more than a smorgasbord of nonsense not even web
dialogs scripting can hold a candle to, but i digress... We need more
than what the CommonDialog classes expose, although some info on CD's
would be helpful. Would you be interested in adding some additional
info to this wonderful site? And What about image acquisition?
 
T

Tim Golden

Hello Tim,

Thanks for posting this wonderful win32 info at your site. I have
used it quite extensively in the past and would like to know if you
are interested in adding a bit more to the code to this simplistic
example...

Thanks for taking the trouble to comment and ask. The challenge
always with putting up examples is deciding the point
at which enough is illustrated to make something useful; as opposed
to a more comprehensive example which then, perhaps, hides the wood
among too many trees. (Or something). My preference, on my own site
and when posting to this group, is towards the former: functional
brevity. Your suggestion for a fleshed-out example involving printer
setup is a good one, I think. Assuming I can find the time, I'll
try to put something together as a separate example.
... We need more than what the CommonDialog classes expose, although
some info on CD's would be helpful. Would you be interested in adding
some additional info to this wonderful site? And What about image
acquisition?

I'm very keen to add things. It just needs the right mixture of
perspiration and inspiration, as the expression has it. Most often
an example here starts as a question on this or the python-win32
lists so thanks for the suggestions. I will add them to the list.
(Of suggestions :) ).

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top