/
pdf2shrink
34 lines (34 loc) · 1.36 KB
/
pdf2shrink
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
#!/usr/bin/env python3
#Created by Alfredo Bonino Under the gpl3 license
import os
from sys import argv
def help():
print("pdf2shrink - A simple utility for compress pdf files")
print("----------------------------------------------------")
print("Created by Alfredo Bonino")
print("The program require pdftk and ghostscript")
print("Under the GPL 3 License")
print("HELP")
print("---------")
print("Usage:\n")
print("pdf2shrink levelofcompression inputfile.pdf outputfile.pdf\n")
print("where levelofcompression are the level of compression of the pdf.")
print("--------------------------------------------------------------------")
print("Levels of compression:")
print("low = low compression (20%*)")
print("medium = medium compression (50%*)")
print("high = high compression (60-70%*)")
print("* = the result may be different!")
if len(argv) > 1:
if argv[1] == "low":
os.system("pdftops " + argv[2] + " temp.ps")
os.system("ps2pdf temp.ps " + argv[3])
os.system("rm temp.ps")
if argv[1] == "medium":
os.system("gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=" + argv[3] + " " + argv[2])
if argv[1] == "high":
os.system("gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=" + argv[3] + " " + argv[2])
if argv[1] == "help":
help()
else:
help()