Skip to content

Instantly share code, notes, and snippets.

@hrsano645
Created July 2, 2015 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrsano645/ddd5c111204338576404 to your computer and use it in GitHub Desktop.
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
# 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