[Tutor] Windows printing

Rance Hall ranceh at gmail.com
Thu Sep 23 08:30:45 CEST 2010


I'm using this page as a reference:
http://timgolden.me.uk/python/win32_how_do_i/print.html

I'm able to print to the default printer ok, but I can't seem to find
out how to get to pick the printer I want to use.

This is from a CLI app, so there is no gui.

win32print seems like it has everything I need, I just can't quite see
how to put it together

I'd like to have my python app ask which printer to use as opposed to
just using the default printer.

win32print.EnumPrinters() does give me a list, but its not just a list
of names. the list also includes other items like network paths
depending on the level of detail you specify in EnumPrinters.


Tim has two possible ways to print.  Tim shows how to use the win32api
to pass a ShellExecute command that prints.  The catch to this command
is you have to print a file type and it has to be the default type for
an app to open.

He also shows a way to skip the ShellExecute and use the print api
directly to gain some more control.

Based on my needs, I'm pretty sure that I'll need to use win32print,


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'm going to be printing automatically generated check-in tickets.

I can make the ticket, save it as a temp file, but I can not print to
the default printer, I must be able to select the destination printer.

My plan is to ask the user what printer to use for the session, and
save that printer name in a variable and direct all automated prints
to that printer.

As we move the laptop from place to place the default printer is not
always available.  And the available printer changes depending on
location.

Ideally there would be a variation of the ShellExecute command that
would let me specify a printer name.

Windows 7 is the predominate windows platform we are using.

Thanks


More information about the Tutor mailing list