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

From: Tim Golden on
On 14/06/2010 16:31, loial wrote:
> What is the easiest way to send a text file to a networked printer
> from a python script running on windows?

http://timgolden.me.uk/python/win32_how_do_i/print.html

TJG
From: rantingrick on
On Jun 14, 10:55 am, Tim Golden <m...(a)timgolden.me.uk> wrote:
> On 14/06/2010 16:31, loial wrote:
>
> > What is the easiest way to send a text file to a networked printer
> > from a python script running on windows?
>
>    http://timgolden.me.uk/python/win32_how_do_i/print.html


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?
From: Tim Golden on
On 14/06/2010 7:29 PM, rantingrick wrote:
> On Jun 14, 10:55 am, Tim Golden<m...(a)timgolden.me.uk> wrote:
>> On 14/06/2010 16:31, loial wrote:
>>
>>> What is the easiest way to send a text file to a networked
>>> printer from a python script running on windows?
>>
>> http://timgolden.me.uk/python/win32_how_do_i/print.html
>
>
> 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