-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtiff2djvu.py
executable file
·154 lines (145 loc) · 5.27 KB
/
tiff2djvu.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#! /usr/bin/env python
#
# tiff2djvu - A software to merge multiple tiff images to a single djvu file
#
# Copyright (c) 2012
# Balasankar C <[email protected]>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import pygtk
import gtk
import sys
import os
class Base:
#Exit Button
def destroy(self,widget,data=None):
if os.path.isdir("tmp"):
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while removing pdfs")
cmnd4="rm -fr tmp"
flag=os.system(cmnd4)
if flag!=0:
md1.run()
md1.destroy()
return
sys.exit()
#Select output file
def outputselect(self,widget):
dialog1=gtk.FileChooserDialog("Name Output File",None,gtk.FILE_CHOOSER_ACTION_SAVE,(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
dialog1.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name("djvu Files")
filter.add_pattern("*.djvu")
dialog1.add_filter(filter)
response = dialog1.run()
self.outputfilename=dialog1.get_filename()
self.out2 = self.outputfilename.split('/')[-1]
dialog1.destroy()
#Selecting input files
def selectfile(self,widget):
dialog=gtk.FileChooserDialog("Select Input Files",None,gtk.FILE_CHOOSER_ACTION_OPEN,(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.set_select_multiple(True)
filter = gtk.FileFilter()
filter.set_name("Tiff Files")
filter.add_pattern("*.tif")
filter.add_pattern("*.tiff")
dialog.add_filter(filter)
response = dialog.run()
if response == gtk.RESPONSE_OK:
self.filelist = dialog.get_filenames()
dialog.destroy()
#Converting tif files to individual pdf files
def convert(self,widget):
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while removing pdfs")
cmnd4="rm -fr tmp"
flag=os.system(cmnd4)
if flag!=0:
md1.run()
md1.destroy()
return
flag=1
if not os.path.isdir("tmp"):
print"creating tmp folder"
os.makedirs("tmp");
j=100
for p in self.filelist:
print p
cmnd = "tiff2pdf -o 'tmp/"+str(j)+self.out2+"_temp.pdf' '"+ p +"'"
flag=os.system(cmnd)
j=j+1
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while creating pdf")
if flag!=0:
md1.run()
md1.destroy()
return
#Merging pdf files to a single pdf files
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while merging pdf")
cmnd2="pdftk tmp/*.pdf cat output 'tmp/"+self.out2+"_file_merged.pdf'"
flag=os.system(cmnd2)
if flag!=0:
md1.run()
md1.destroy()
return
#Converting pdf file to djvu file
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while creating djvu")
cmnd3="pdf2djvu -o "+self.outputfilename+".djvu 'tmp/"+self.out2+"_file_merged.pdf'"
flag=os.system(cmnd3)
if flag!=0:
md1.run()
md1.destroy()
return
j=100
md1= gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE, "Error while removing pdfs")
cmnd4="rm -fr tmp"
flag=os.system(cmnd4)
if flag!=0:
md1.run()
md1.destroy()
return
md = gtk.MessageDialog(None,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO,gtk.BUTTONS_CLOSE, "Successfully Converted")
md.run()
#Displaying successful message
md.destroy()
def __init__(self):
#Main function
self.flag=0
self.window = gtk.Window()
self.window.set_position(gtk.WIN_POS_CENTER)
self.windowx,self.windowy = self.window.get_position()
self.windowheight,self.windowwidth = self.window.get_size()
self.window.show()
self.fixed = gtk.Fixed()
self.window.connect("destroy",self.destroy)
self.button4=gtk.Button("Exit")
self.button1 = gtk.Button("Open")
self.button3 = gtk.Button("Convert")
self.button2 = gtk.Button("Choose Output File")
self.button3.connect("clicked",self.convert)
self.button4.connect("clicked",self.destroy)
self.button1.connect("clicked",self.selectfile)
self.button2.connect("clicked",self.outputselect)
self.button3.set_size_request(150,50)
self.button1.set_size_request(150,50)
self.button2.set_size_request(150,50)
self.button4.set_size_request(150,50)
self.fixed.put(self.button1,30,30)
self.fixed.put(self.button2,30,100)
self.fixed.put(self.button4,30,240)
self.fixed.put(self.button3,30,170)
self.filelist=""
self.window.add(self.fixed)
self.window.show_all()
def main(self):
gtk.main()
if __name__ == "__main__":
base= Base()
base.main()