File size: 390 Bytes
2ae875f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import fitz 
import os 
pdf_file_path="sample/GB.pdf"
pdf=fitz.open(pdf_file_path)

save_dir="cache/GB"
os.makedirs(save_dir,exist_ok=True)
for page_num in range(len(pdf)):
    page=pdf[page_num]
    pix=page.get_pixmap()
    image_filename=os.path.join(save_dir,f"{os.path.splitext(os.path.basename(pdf_file_path))[0]}_page_{page_num+1}.png")
    pix.save(image_filename)
    

pdf.close()