summaryrefslogtreecommitdiff
path: root/MAT/office.py
diff options
context:
space:
mode:
authorjvoisin2013-10-27 16:07:10 +0000
committerjvoisin2013-10-27 16:07:10 +0000
commita4f80082885079351d71bd3b6c3eaae1fcd5258f (patch)
tree9c00efaa5d45c63867876c6844309f68452e3a44 /MAT/office.py
parenteb674c984bbd2920e169134945ef18020acfb662 (diff)
Improve MAT's reliability
Diffstat (limited to '')
-rw-r--r--MAT/office.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/MAT/office.py b/MAT/office.py
index c44a52b..583e0f9 100644
--- a/MAT/office.py
+++ b/MAT/office.py
@@ -156,23 +156,27 @@ class PdfStripper(parser.GenericParser):
156 python-cairo segfaults on unicode. 156 python-cairo segfaults on unicode.
157 See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699457 157 See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699457
158 ''' 158 '''
159 output = tempfile.mkstemp()[1] 159 try:
160 page = self.document.get_page(0) 160 output = tempfile.mkstemp()[1]
161 # assume that every pages are the same size 161 page = self.document.get_page(0)
162 page_width, page_height = page.get_size() 162 # assume that every pages are the same size
163 surface = cairo.PDFSurface(output, page_width, page_height) 163 page_width, page_height = page.get_size()
164 context = cairo.Context(surface) # context draws on the surface 164 surface = cairo.PDFSurface(output, page_width, page_height)
165 logging.debug('PDF rendering of %s' % self.filename) 165 context = cairo.Context(surface) # context draws on the surface
166 for pagenum in range(self.document.get_n_pages()): 166 logging.debug('PDF rendering of %s' % self.filename)
167 page = self.document.get_page(pagenum) 167 for pagenum in range(self.document.get_n_pages()):
168 context.translate(0, 0) 168 page = self.document.get_page(pagenum)
169 if self.pdf_quality: 169 context.translate(0, 0)
170 page.render(context) # render the page on context 170 if self.pdf_quality:
171 else: 171 page.render(context) # render the page on context
172 page.render_for_printing(context) # render the page on context 172 else:
173 context.show_page() # draw context on surface 173 page.render_for_printing(context) # render the page on context
174 surface.finish() 174 context.show_page() # draw context on surface
175 shutil.move(output, self.output) 175 surface.finish()
176 shutil.move(output, self.output)
177 except:
178 logging.error('Something went wrong when cleaning %s. File not cleaned' % self.filename)
179 return False
176 180
177 try: 181 try:
178 import pdfrw # For now, poppler cannot write meta, so we must use pdfrw 182 import pdfrw # For now, poppler cannot write meta, so we must use pdfrw