-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress_latex.py
executable file
·56 lines (49 loc) · 1.57 KB
/
compress_latex.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import sys
import utool as ut
from os.path import join, dirname, abspath, basename
#def find_ghostscript_exe():
# if ut.WIN32:
# gs_exe = r'C:\Program Files (x86)\gs\gs9.16\bin\gswin32c.exe'
# else:
# gs_exe = 'gs'
# return gs_exe
#def compress_pdf(pdf_fpath, output_fname=None):
# """ uses ghostscript to write a pdf """
# ut.assertpath(pdf_fpath)
# suffix = '_' + ut.get_datestamp(False) + '_compressed'
# print('pdf_fpath = %r' % (pdf_fpath,))
# output_pdf_fpath = ut.augpath(pdf_fpath, suffix, newfname=output_fname)
# print('output_pdf_fpath = %r' % (output_pdf_fpath,))
# gs_exe = find_ghostscript_exe()
# cmd_list = (
# gs_exe,
# '-sDEVICE=pdfwrite',
# '-dCompatibilityLevel=1.4',
# '-dNOPAUSE',
# '-dQUIET',
# '-dBATCH',
# '-sOutputFile=' + output_pdf_fpath,
# pdf_fpath
# )
# ut.cmd(*cmd_list)
# return output_pdf_fpath
if __name__ == '__main__':
"""
CommandLine:
./compress_latex.py
"""
if len(sys.argv) == 1:
abs_file = abspath(__file__)
pdf_fpath = join(dirname(abs_file), 'main.pdf')
output_fname = basename(dirname(abs_file))
import re
output_fname = re.sub('\d', '', output_fname).strip('-').strip('_')
else:
pdf_fpath = sys.argv[1]
output_fname = None
output_pdf_fpath = ut.compress_pdf(pdf_fpath, output_fname=output_fname)
PUBLISH = True
if PUBLISH:
publish_path = ut.truepath('~/Dropbox/crall')
ut.copy(output_pdf_fpath, publish_path)