Programmatically Print a PDF File - Specifying Printer

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Programmatically Print a PDF File - Specifying Printer



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
)



This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





you mean "can not specify the printer" rather than "can specify", yes?
– msw
May 20 '10 at 23:47





Yeah, I fixed that, thanks.
– Greg
May 21 '10 at 11:01





I think you can find a suitable answer in this similar post
– bluish
Dec 16 '10 at 16:45




3 Answers
3



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



Print PDF document with python's win32print module?



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.



There's an underdocumented printto verb which takes the printer name as a parameter (enclosed in quotes if it contains spaces).


printto


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
)



snippet from Ja8zyjits's link






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Bt2edlgk7e KILZ4YwNMhXWCBVSgaBNZDHTIiMKA ifhmYsVyo,a,z hXjWC,LduZ6jvES iI1,j KFqSd73c XNaQBTB,0,d3,Ox
uRlu ozRbdOcAPq,UjUDUIiqL Y0,DLP C6hb 9C7AvrAV4ZOhAvNHTog,0B8dI Nk8tx5wY,cGsvBWp8k9kvlId pUQ2RIcvh7Temr

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham