Reputation: 47094
I have a requirement to print an existing PDF file from a Python script.
I need to be able to specify the printer in the script. It's running on Windows XP.
Any ideas what I could do?
This method looks like it would work except that I cannot specify the printer:
win32api.ShellExecute (
0,
"print",
filename,
None,
".",
0
)
Upvotes: 5
Views: 17193
Reputation: 2820
There's an underdocumented printto
verb which takes the printer name as a parameter (enclosed in quotes if it contains spaces).
import tempfile
import win32api
import win32print
filename = tempfile.mktemp (".txt")
open (filename, "w").write ("This is a test")
win32api.ShellExecute (
0,
"printto",
filename,
'"%s"' % win32print.GetDefaultPrinter (),
".",
0
)
Upvotes: 3
Reputation: 1503
please refer this link for further details
import tempfile
import win32api
import win32print
filename = tempfile.mktemp (".txt")
open (filename, "w").write ("This is a test")
win32api.ShellExecute (
0,
"print",
filename,
#
# If this is None, the default printer will
# be used anyway.
#
'/d:"%s"' % win32print.GetDefaultPrinter (),
".",
0
)
This shall work please refer the link provided for further details.
Upvotes: 1
Reputation: 768
Looks like bluish left a comment about this but did not leave an answer.
Install Ghostprint http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm
Then use the command in the question
Upvotes: 1