I want to save my output data into the text file where each new line is shown in a different row. Currently each row is delimited by \n, I want new lines to be saved in different rows.
from PIL import Image 
import pytesseract 
import sys 
from pdf2image import convert_from_path 
import os 
PDF_file = "F:/ABC/Doc_1.pdf"
pages = convert_from_path(PDF_file, 500) 
image_counter = 1
for page in pages: 
    filename = "page_"+str(image_counter)+".jpg"
    page.save(filename, 'JPEG') 
    image_counter = image_counter + 1
filelimit = image_counter-1
outfile = "F:/ABC/intermediate_steps/out_text.txt"
f = open(outfile, "a") 
for i in range(1, 2): 
    filename = "page_"+str(i)+".jpg"
    import pytesseract 
    pytesseract.pytesseract.tesseract_cmd = r"\ABC\opencv-text-detection\Tesseract-OCR\tesseract.exe"
    from pytesseract import pytesseract
    text = str(((pytesseract.image_to_string(Image.open(filename)))))  
    text = text.replace('-\n', '')   
    #text = text.splitlines()
    f.writelines("Data Extracted from next page starts now.")
    f.writelines(str(text.encode('utf-8')))
f.close() 
For eg :-
ABC
DEF
GHI
Current output :-
ABC\nDEF\nGHI\n

 
     
    