Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'PdfPage' object has no attribute 'render_topil'

Tags:

python

pdf

I am using pypdfium2 version 4.5.0, I am facing this problem

I want to make use of this render_topil

pdf = pdfium.PdfDocument(pdf_path)
page = pdf.get_page(0)
pil_image = page.render_topil(scale = 300/72)
image_name = f"Images/{image_name}.jpg"
pil_image.save(image_name)
like image 343
VigneshKumar Selvaraj Avatar asked Oct 28 '25 04:10

VigneshKumar Selvaraj


1 Answers

Pypdfium2 version 4 removed the render_topil method. As of version 4.9.0 the correct way to convert a Pypdfium2 Page object to PIL image following your code snippet is:

pdf = pdfium.PdfDocument(pdf_path)
page = pdf.get_page(0)
pil_image = page.render(scale = 300/72).to_pil()
image_name =f"Images/{image_name}.jpg"
pil_image.save(image_name)
like image 186
RakuJa Avatar answered Oct 29 '25 18:10

RakuJa