Created
July 2, 2015 12:25
-
-
Save hrsano645/ddd5c111204338576404 to your computer and use it in GitHub Desktop.
Printing PDF File at windows and python. Use subprocess module and Adobe Acrobat Commandline Option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from __future__ import division, print_function, absolute_import, unicode_literals | |
import subprocess | |
import sys | |
# ref: https://geonet.esri.com/thread/59446 | |
# ref: https://helpx.adobe.com/jp/acrobat/kb/510705.html | |
def main(pdffile): | |
# acroread = r'C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe' | |
acrobat = r'C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe' | |
# '"%s"'is to wrap double quotes around paths | |
# as subprocess will use list2cmdline internally if we pass it a list | |
# which escapes double quotes and Adobe Reader doesn't like that | |
cmd = '"{}" /P "{}"'.format(acrobat, pdffile) | |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdout, stderr = proc.communicate() | |
exit_code = proc.wait() | |
if __name__ == '__main__': | |
pdffile = sys.argv[1] | |
main(pdffile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment