Пример #1
0
    def __render_img(self, factor):
        # TODO(Jflesch): In a perfect world, we shouldn't use ImageSurface.
        # we should draw directly on the GtkImage.window.cairo_create()
        # context. It would be much more efficient.

        if factor not in self.__img_cache:
            logger.debug('Building img from pdf with factor: %s' % factor)
            width = int(factor * self._size[0])
            height = int(factor * self._size[1])

            surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
            ctx = cairo.Context(surface)
            ctx.scale(factor, factor)
            self.pdf_page.render(ctx)
            self.__img_cache[factor] = surface2image(surface)
        return self.__img_cache[factor]
Пример #2
0
    def refresh(self):
        # make the preview

        tmp = "%s.%s" % (os.tempnam(None,
                                    "paperwork_export_"), self.valid_exts[0])
        path = self.__save(tmp, pages=(0, 1))

        # reload the preview

        pdfdoc = Poppler.Document.new_from_file(
            ("file://%s" % urllib.quote(path)), password=None)
        assert (pdfdoc.get_n_pages() > 0)

        pdfpage = pdfdoc.get_page(0)
        pdfpage_size = pdfpage.get_size()

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(pdfpage_size[0]),
                                     int(pdfpage_size[1]))
        ctx = cairo.Context(surface)
        pdfpage.render(ctx)
        img = surface2image(surface)

        self.__preview = (path, img)