【发布时间】:2021-08-08 17:44:56
【问题描述】:
上下文:
我有正在处理的 PDF 文件。
我正在使用ocr 从这些文档中提取文本,为了能够做到这一点,我必须将我的 pdf 文件转换为图像。
我目前使用pdf2image 模块的convert_from_path 功能,但它的时间效率非常低(9 页 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)
Link 到 convert_from_path 引用。
【问题讨论】:
标签: python image pdf ocr pdf2image