summaryrefslogtreecommitdiff
path: root/libmat
diff options
context:
space:
mode:
authorjvoisin2015-04-04 17:52:19 +0200
committerjvoisin2015-04-04 17:52:19 +0200
commiteb21be97ac1cd4fea48cf719393fd103f11c1594 (patch)
treed4b97c96d40b20f059db97cc3a2238ad252f2199 /libmat
parent0fa7dce07eecaaa089cbb2a6c124b81173ace0aa (diff)
Fix #9007
The MAT can now handle PDf with different pages size. Also, instead of being overwritten, context are now pushed/poped instead.
Diffstat (limited to 'libmat')
-rw-r--r--libmat/office.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/libmat/office.py b/libmat/office.py
index 0ca1ff1..2f6fff0 100644
--- a/libmat/office.py
+++ b/libmat/office.py
@@ -145,19 +145,24 @@ class PdfStripper(parser.GenericParser):
145 document = Poppler.Document.new_from_file(self.uri, self.password) 145 document = Poppler.Document.new_from_file(self.uri, self.password)
146 try: 146 try:
147 output = tempfile.mkstemp()[1] 147 output = tempfile.mkstemp()[1]
148 page = document.get_page(0) 148
149 # assume that every pages are the same size 149 # Size doesn't matter (pun intended),
150 page_width, page_height = page.get_size() 150 # since the surface will be resized before
151 surface = cairo.PDFSurface(output, page_width, page_height) 151 # being rendered
152 surface = cairo.PDFSurface(output, 10, 10)
152 context = cairo.Context(surface) # context draws on the surface 153 context = cairo.Context(surface) # context draws on the surface
154
153 logging.debug('PDF rendering of %s' % self.filename) 155 logging.debug('PDF rendering of %s' % self.filename)
154 for pagenum in range(document.get_n_pages()): 156 for pagenum in range(document.get_n_pages()):
155 page = document.get_page(pagenum) 157 page = document.get_page(pagenum)
156 context.translate(0, 0) 158 page_width, page_height = page.get_size()
157 if self.pdf_quality: 159 surface.set_size(page_width, page_height)
158 page.render(context) # render the page on context 160 context.save()
161 if self.pdf_quality: # this may reduce the produced PDF size
162 page.render(context)
159 else: 163 else:
160 page.render_for_printing(context) # render the page on context 164 page.render_for_printing(context)
165 context.restore()
161 context.show_page() # draw context on surface 166 context.show_page() # draw context on surface
162 surface.finish() 167 surface.finish()
163 shutil.move(output, self.output) 168 shutil.move(output, self.output)