Recently, I took a project. Converting a scanned PDF to searchable PDF/word using Python tesseract.
After few attempts, I could able to convert scanned PDF to PNG image files and afterwards, I'm struck could anyone please help me to convert the PNG files to Word/PDF searchable.my piece of code attached
Please find the attached image for reference.
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))
that's it, I've written.....then I got multiple ".PNG" images...now I can only able to convert one PNG images to text.
How to convert all the images and save it in CSV/word?
I got answer to my question