File size: 297 Bytes
80be769
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import fitz
from PIL import Image

def page2image(page: fitz.Page, dpi: int = 72):
    # Convert page to pixmap
    pix = page.get_pixmap(dpi=dpi)

    # Convert pixmap to PIL Image
    img = Image.frombytes(
        "RGB",
        (pix.width, pix.height),
        pix.samples
    )
    return img