Print pdf file to "Adobe pdf" printer using python 2.7.5

I am trying to print a pdf file to the "Adobe pdf" printer from within python 2.7.5 script. By doing so, the file size is drastically reduced.

File name and path is:

pdfdoc = theDir + "" + clientName + "-Stats.pdf"

Suggestions as to how to approach this?

I tried the following code but since it is printing to the "Adobe pdf" printer, I get a "save as" dialog box, which I don't want.

from subprocess import call

acrobat = "C:Program Files (x86)AdobeAcrobat 10.0AcrobatAcrobat.exe"
pdfdoc = theDir + "" + clientName + "-Stats.pdf"
printer = "Adobe pdf"

call([acrobat, "/T", pdfdoc, printer])

The way I got around this was to open Printer Preferences for the Adobe PDF driver (Control PanelHardware and SoundDevices and Printers) and manually set the Adobe PDF Output Folder. See screenshot below link to screenshot:

Adobe PDF Driver Printer Preferences

I also deselected "View Results" but that's optional.

You may need to also rename the new PDF file. I accomplished this using shutil and renaming while moving the file to a different directory but you could also use os.rename(). I don't know how to access Adobe through Python to input the new filename during printing, but I suspect this is possible somehow.

Hope this helps.

链接地址: http://www.djcxy.com/p/55076.html

上一篇: 如果它包含特定的字母/字符,则替换整个字符串

下一篇: 使用python 2.7.5将pdf文件打印成“Adobe pdf”打印机