简体   繁体   English

使用python 2.7.5将pdf文件打印到“ Adob​​e pdf”打印机

[英]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. 我正在尝试从python 2.7.5脚本中将pdf文件打印到“ Adob​​e pdf”打印机。 By doing so, the file size is drastically reduced. 这样,文件大小将大大减少。

File name and path is: 文件名和路径为:

pdfdoc = theDir + "\\" + clientName + "-Stats.pdf" 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. 我尝试了以下代码,但是由于它正在打印到“ Adob​​e pdf”打印机,所以我得到了一个“另存为”对话框,我不需要。

from subprocess import call

acrobat = "C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.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 Panel\\Hardware and Sound\\Devices and Printers) and manually set the Adobe PDF Output Folder. 解决此问题的方法是打开Adobe PDF驱动程序的“打印机首选项”(“控制面板” \\“硬件和声音” \\“设备和打印机”),然后手动设置Adobe PDF输出文件夹。 See screenshot below link to screenshot: 请参阅下面的屏幕快照,链接至屏幕快照:

Adobe PDF Driver Printer Preferences Adobe PDF驱动程序打印机首选项

I also deselected "View Results" but that's optional. 我还取消选择了“查看结果”,但这是可选的。

You may need to also rename the new PDF file. 您可能还需要重命名新的PDF文件。 I accomplished this using shutil and renaming while moving the file to a different directory but you could also use os.rename(). 在将文件移动到其他目录时,我使用了shutil和重命名来完成此操作,但是您也可以使用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. 我不知道如何在打印过程中通过Python访问Adobe来输入新文件名,但是我怀疑这是有可能的。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM