forked from ppwwyyxx/SoPaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf-compress.py
executable file
·38 lines (31 loc) · 948 Bytes
/
pdf-compress.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
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: pdf-compress.py
# Date: Mon Jun 01 01:32:07 2015 +0800
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import sys
import os
import os.path
import argparse
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
'common'))
from lib.pdfutil import pdf_compress
def get_args():
desc = 'Compress Pdf By ps2pdf'
parser = argparse.ArgumentParser(description = desc)
parser.add_argument('file', help='file name')
ret = parser.parse_args()
return ret
def main():
global args
args = get_args()
data = open(args.file).read()
newdata = pdf_compress(data)
if len(newdata) < len(data):
newfilename = args.file + '.compressed'
with open(newfilename, 'w') as fout:
fout.write(newdata)
os.remove(args.file)
os.rename(newfilename, args.file)
if __name__ == '__main__':
main()