12/01/2021

pdf2img, pdf to image, python library

 way #1

--

# pip install pdf2image
from pdf2image import convert_from_path
pdffile = '2081033884.pdf'
pages = convert_from_path(pdffile, 500)
#Saving pages in jpeg format
for i, page in enumerate(pages):
page.save(f'pdf2image_{i}.jpg', 'JPEG')

--



way #2

--

#pip install pymupdf
import fitz
pdffile = '2081033884.pdf'
doc = fitz.open(pdffile)
#split pages
for i, page in enumerate(doc.pages()):
pix = page.get_pixmap()
img_filename = f"fitz_{i}.jpg"
pix.pil_save(img_filename, format="jpeg", dpi=(300,300)) #, ... more PIL parameters)

--


Thank you.

www.marearts.com

πŸ™‡πŸ»‍♂️