summaryrefslogtreecommitdiff
path: root/MAT
diff options
context:
space:
mode:
authorjvoisin2013-04-05 10:55:34 +0200
committerjvoisin2013-04-05 10:55:34 +0200
commit3d8e11ce644833106f22778f3171c52a51ff69fe (patch)
treed1d1476407abbba27e9e365da3fe7fee2ca4022a /MAT
parentb2ff71a5626b0c955db15fe21426f71150fe7fda (diff)
Pdf support is back
Diffstat (limited to 'MAT')
-rw-r--r--MAT/office.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/MAT/office.py b/MAT/office.py
index b74b49c..a861919 100644
--- a/MAT/office.py
+++ b/MAT/office.py
@@ -6,6 +6,8 @@ import os
6import logging 6import logging
7import zipfile 7import zipfile
8import fileinput 8import fileinput
9import tempfile
10import shutil
9import xml.dom.minidom as minidom 11import xml.dom.minidom as minidom
10 12
11try: 13try:
@@ -145,11 +147,16 @@ class PdfStripper(parser.GenericParser):
145 147
146 http://cairographics.org/documentation/pycairo/2/ 148 http://cairographics.org/documentation/pycairo/2/
147 python-poppler is not documented at all : have fun ;) 149 python-poppler is not documented at all : have fun ;)
150
151 The use of an intermediate tempfile is necessary because
152 python-cairo segfaults on unicode.
153 See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699457
148 ''' 154 '''
155 output = tempfile.mkstemp()[1]
149 page = self.document.get_page(0) 156 page = self.document.get_page(0)
150 # assume that every pages are the same size 157 # assume that every pages are the same size
151 page_width, page_height = page.get_size() 158 page_width, page_height = page.get_size()
152 surface = cairo.PDFSurface(self.output, page_width, page_height) 159 surface = cairo.PDFSurface(output, page_width, page_height)
153 context = cairo.Context(surface) # context draws on the surface 160 context = cairo.Context(surface) # context draws on the surface
154 logging.debug('PDF rendering of %s' % self.filename) 161 logging.debug('PDF rendering of %s' % self.filename)
155 for pagenum in xrange(self.document.get_n_pages()): 162 for pagenum in xrange(self.document.get_n_pages()):
@@ -161,6 +168,7 @@ class PdfStripper(parser.GenericParser):
161 page.render_for_printing(context) # render the page on context 168 page.render_for_printing(context) # render the page on context
162 context.show_page() # draw context on surface 169 context.show_page() # draw context on surface
163 surface.finish() 170 surface.finish()
171 shutil.move(output, self.output)
164 172
165 try: 173 try:
166 import pdfrw # For now, poppler cannot write meta, so we must use pdfrw 174 import pdfrw # For now, poppler cannot write meta, so we must use pdfrw