[Tutor] Windows printing

Rance Hall ranceh at gmail.com
Thu Sep 23 15:05:14 CEST 2010

On Thu, Sep 23, 2010 at 3:40 AM, Tim Golden <mail at timgolden.me.uk> wrote:
> On 23/09/2010 07:30, Rance Hall wrote:
>> Tim's how-to is likely not for my version of python (mine is 3.1)
>> since some of his command fail on my system because mine wants options
>> or parameters that Tim doesn't mention.
> I've fixed one issue: the win32print example now passes bytes for Py3.x
> and str for 2.x; that example now works for me. I haven't worked through
> the other examples yet but thanks for the heads-up.

Thanks for the rapid turn around on this one.


> OK. Thanks for the fairly clear explanation of the situation. I agree
> that a ShellExecute variant which allowed printer selection would be
> good, but I don't believe there is one. That's basically because
> ShellExecute is really what the user indirectly actions when they
> double-click or right-click on a file and choose one of the actions:
> there's no scope for additional info within the ShellExecute mechanism.
> Obviously a program called in this way is free to do whatever it wishes
> in the way of selection dialogs and the like.
> One thing which isn't entirely clear to me is whether your ticket-saved-
> as-a-temp-file is printer-ready, eg plain text, PS or PCL, or whether
> you'd really want to format it further before printing. On the basis
> that it's ready to go direct, the following very slight variation should
> do what I think you want: (tested only on XP; I'll try to get hold of
> a W7 machine to double-check)

For the first roll-out and testing I figured plaintext was good enough.

Future revisions will probably use the PDF library you also referred
to on your page.

Either way that is as printer ready as I expect I will be able to get it.

> <code>
> import os, sys
> import win32print
> printer_info = win32print.EnumPrinters (
> )
> printer_names = [name for (flags, description, name, comment) in
> printer_info]
> for i, name in enumerate (printer_names):
>  print ("%d) %s" % (i + 1, name))
> n_printer = int (input ("Which printer: "))
> printer_name = printer_names[n_printer+1]
> print ("Using", printer_name)
> hPrinter = win32print.OpenPrinter (printer_name)
> #
> # ... and so on, per the original example
> #
> </code>
> Is this what you're after? Or have I missed the point?

This has the logic of what I want, I'll test it later today on Win7
and see if I have any issues I can't resolve, I tried some of this
from the python console and dont get any errors, so it lools

Thanks again for the rapid response.

More information about the Tutor mailing list