语境:
我有正在使用的 PDF 文件。我正在使用ocr
从这些文档中提取文本并且能够做到这一点,我必须将我的 pdf 文件转换为图像。我目前使用模块的convert_from_path
功能,pdf2image
但时间效率非常低(9page pdf 需要 9 分钟)。
问题:
我正在寻找一种方法来加速此过程或另一种将我的 PDF 文件转换为图像的方法。
附加信息:
我知道thread_count
函数中有一个参数,但经过几次尝试,它似乎没有任何区别。
这是我正在使用的整个功能:
def pdftoimg(fic,output_folder):
# Store all the pages of the PDF in a variable
pages = convert_from_path(fic, dpi=500,output_folder=output_folder,thread_count=9, poppler_path=r'C:\Users\Vincent\Documents\PDF\poppler-21.02.0\Library\bin')
image_counter = 0
# Iterate through all the pages stored above
for page in pages:
filename = "page_"+str(image_counter)+".jpg"
page.save(output_folder+filename, 'JPEG')
image_counter = image_counter + 1
for i in os.listdir(output_folder):
if i.endswith('.ppm'):
os.remove(output_folder+i)
链接到 convert_from_path 参考。