GhostScript performs much faster than Poppler for a Linux based system.
Following is the code for pdf to image conversion.
def get_image_page(pdf_file, out_file, page_num):
page = str(page_num + 1)
command = ["gs", "-q", "-dNOPAUSE", "-dBATCH", "-sDEVICE=png16m", "-r" + str(RESOLUTION), "-dPDFFitPage",
"-sOutputFile=" + out_file, "-dFirstPage=" + page, "-dLastPage=" + page,
pdf_file]
f_null = open(os.devnull, 'w')
subprocess.call(command, stdout=f_null, stderr=subprocess.STDOUT)
GhostScript can be installed on macOS using brew install ghostscript
Installation information for other platforms can be found here. If it is not already installed on your system.
fitz
that outputs PNG is substantially lower quality than the accepted one using JPG. I suspect the image resolutions are resized per PDF paper size. – Rifle