From eb21be97ac1cd4fea48cf719393fd103f11c1594 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 4 Apr 2015 17:52:19 +0200 Subject: Fix #9007 The MAT can now handle PDf with different pages size. Also, instead of being overwritten, context are now pushed/poped instead. --- libmat/office.py | 21 +++++++++++++-------- 1 file 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): document = Poppler.Document.new_from_file(self.uri, self.password) try: output = tempfile.mkstemp()[1] - page = document.get_page(0) - # assume that every pages are the same size - page_width, page_height = page.get_size() - surface = cairo.PDFSurface(output, page_width, page_height) + + # Size doesn't matter (pun intended), + # since the surface will be resized before + # being rendered + surface = cairo.PDFSurface(output, 10, 10) context = cairo.Context(surface) # context draws on the surface + logging.debug('PDF rendering of %s' % self.filename) for pagenum in range(document.get_n_pages()): page = document.get_page(pagenum) - context.translate(0, 0) - if self.pdf_quality: - page.render(context) # render the page on context + page_width, page_height = page.get_size() + surface.set_size(page_width, page_height) + context.save() + if self.pdf_quality: # this may reduce the produced PDF size + page.render(context) else: - page.render_for_printing(context) # render the page on context + page.render_for_printing(context) + context.restore() context.show_page() # draw context on surface surface.finish() shutil.move(output, self.output) -- cgit v1.3