import sys import os from PIL import Image import ocrmypdf filepath1 = input(" Enter the File path: ") filepath = filepath1 + "\\" filelist = os.path.isdir(filepath) langu = filepath + "lang.ini" for fname in os.listdir(filepath): print(fname) if not fname.endswith(".tif"): continue input_file = os.path.join(filepath, fname) im1 = Image.open(input_file).convert("RGB") pname = os.path.splitext(fname)[0] output_file = filepath + pname + ".pdf" f1 = open(output_file, "w+b") with open(langu) as f: # open the ini file ini = f.read() # read the ini file ocrmypdf.ocr(input_file, output_file, language=ini, force_ocr=True, output="pdf", jpeg_quality="100") f1.close()