Print PDF document with python’s win32print module?

I ended up using Ghostscript to accomplish this task. There is a command line tool that relies on Ghostscript called gsprint.

You don’t even need Acrobat installed to print PDFs in this fashion which is quite nice.

Here is an example:

on the command line:

gsprint -printer \\server\printer "test.pdf"

from python:

win32api.ShellExecute(0, 'open', 'gsprint.exe', '-printer "\\\\' + self.server + '\\' + self.printer_name + '" ' + file, '.', 0)

Note that I’ve added to my PATH variable in these examples, so I don’t have to include the entire path when calling the executable.

There is one downside, however. The code is licensed under the GPL, so it’s no very useful in commercial software.

Hope this helps someone,
Pete

Leave a Comment