diff options
Diffstat (limited to 'libmat/office.py')
| -rw-r--r-- | libmat/office.py | 21 |
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) |
