Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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)
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)