File size: 741 Bytes
d28ba37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pypdfium2 as pdfium


def pdf_to_image(pdf_name, IMAGES_DIR):
    pdf = pdfium.PdfDocument(pdf_name)
    n_pages = len(pdf)

    for page_number in range(n_pages):
        page = pdf.get_page(page_number)

        scale_value = 3
        pil_image = page.render_to(
            pdfium.BitmapConv.pil_image,
            scale = scale_value,
            rotation = 0,
            fill_colour=(255, 255, 255, 255),
            crop=(0, 0, 0, 0),
            greyscale=False,
            optimise_mode=pdfium.OptimiseMode.NONE,)

        imagename = IMAGES_DIR + str(page_number + 1) + ".png"
        print(imagename)
        pil_image.save(imagename)
        return imagename
        
# pdf_to_image('junks\\Attention is all u need.pdf')