-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathto_pdf.py
31 lines (25 loc) · 960 Bytes
/
to_pdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8
import os
import subprocess
import argparse
office_exes = ["/Applications/LibreOffice.app/Contents/MacOS/soffice", "C:/Program Files (x86)/LibreOffice 5/program/soffice.exe"]
def main():
parser = argparse.ArgumentParser(prog='to_pdf', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--bin', '-b', help="Libre Office binary")
parser.add_argument('--files', '-f', default="*.odp", help="the files to convert")
args = parser.parse_args()
bin = args.bin
if bin is None:
for e in office_exes:
exists = os.path.exists(e)
if exists:
bin = e
break
if bin:
cmd = "{} --headless --convert-to pdf {}".format(bin, args.files)
print cmd
process = subprocess.call(cmd, shell=True)
else:
print "couldn't find a Libre Office binary to convert files to pdf"
if __name__ == '__main__':
main()