Python win32api print only printer by default

I am trying to use win32api to output a pdf document to a specific printer.

 win32api.ShellExecute(0, "print", filename, '/d:"%s"' % printername, ".", 0) 

filename is the fully qualified name of the file path, and printname is the name of the destination printer that I get by looking at the output of win32api.EnumPrinters(6) .

The file is sent to the default Windows printer, even if printername is the name of a different destination (I expect that transferring a specific printer will send the named file to this printer, not the default).

Any hints on what I'm doing wrong? Is there any other way to typically print a PDF file to a specific printer? Banning everything else, is there a way to temporarily change the default printer from my program?

+4
source share
2 answers

MikeHunter's answer was a decent starting point.

The proposed solution calls Acrobat or Acrobat Reader to actually print, not to go through win32api . For my purposes this is enough:

 from subprocess import call acrobat = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat.exe" ## Acrobat reader would also work, apparently file = "C:\path\to\my\file.pdf" printer = "Printer Name Goes Here" call([acrobat, "/T", file, printer]) 

This will launch Acrobat and print the given file to a named printer, even if it is not Windows by default. The first print job processed in this way takes a few seconds (I assume this is a running and cached Acrobat service), subsequent jobs print instantly. I have not performed any load tests, but I assume that the call is less than trivial, so do not trust it for massive bandwidth.

+2
source

Try answering from lpinner at this link: http://forums.arcgis.com/threads/67064-Print-PDFs-with-Python

I tried and it works very well.

Good luck, Mike

0
source

Source: https://habr.com/ru/post/1436662/


All Articles