How to use the paperwork-backend.paperwork_backend.util.surface2image function in paperwork-backend

To help you get started, we’ve selected a few paperwork-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
# reload the preview

        file = Gio.File.new_for_uri(path)
        pdfdoc = Poppler.Document.new_from_gfile(file, 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)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / pdf / page.py View on Github external
if pdf_page is None:
            pdf_page = self.pdf_page

        base_size = self.get_base_size(pdf_page)

        width = int(size[0])
        height = int(size[1])
        factor_w = width / base_size[0]
        factor_h = height / base_size[1]

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        ctx = cairo.Context(surface)
        ctx.scale(factor_w, factor_h)
        pdf_page.render(ctx)
        return surface2image(surface)