【发布时间】:2019-10-30 14:09:43
【问题描述】:
最近,我接了一个项目。使用 Python tesseract 将扫描的 PDF 转换为可搜索的 PDF/word。
经过几次尝试,我可以将扫描的 PDF 转换为 PNG 图像文件,然后我很震惊,谁能帮我将 PNG 文件转换为可搜索的 Word/PDF。my piece of code attached
请查找附件图片以供参考。
Import os
Import sys
from PIL import image
Import pytesseract
from pytesseract import image_to_string
Libpath =r'_______' #site-package
Pop_path=r'_______' #poppler dlls
Sys.path.insert(0,LibPath)
from pdf2image import convert_from_path
Pdfpath=r'_______' # PDF file directory
imgpath=r'_______' #image output path
images= convert_from_path(pdf_path = pdfpath,
dpi=500, poppler_path= pop_path)
for idx, of in enumerate (images):
pg.save(imgPath+'PDF_Page_'+'.png',"PNG")
print('{} page converted'.format(str(idx)))
try:
from PIL import image
except ImportError:
import image
import pytesseract
def ocr-core(images):
Text =
pytesseract.image_to_string(image.open(images))
return text
print(ocr_core("image path/imagename))
就是这样,我已经写了.....然后我得到了多个“.PNG”图像......现在我只能将一个 PNG 图像转换为文本。
如何将所有图片转换成 CSV/word 格式?
【问题讨论】:
-
如果您在此处复制/粘贴代码会更好。如果您描述当前遇到的结果/错误也会很有帮助。
标签: python-3.x python-tesseract pytesser img2pdf