Hi,
I have done a code for extracting the text from an image and writing in a text file using MODI and OCR. But the problem is, i need to install microsoft office 2007 with adding MDIVWCTL.DLL. I dont want to use OCR and MODI. Please help me to extract text lines from a particular image directly without using OCR method and write it into a .txt file.
Code below :
public static void CheckFileType(string directoryPath)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
while (files.MoveNext())
{
string fileExtension = Path.GetExtension(Convert.ToString(files.Current));
string fileName =
Convert.ToString(files.Current).Replace(fileExtension,string.Empty);
if (fileExtension == ".jpg" || fileExtension == ".JPG")
{
try
{
MODI.Document md = new MODI.Document();
md.Create(Convert.ToString(files.Current));
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image image = (MODI.Image)md.Images[0];
//create text file with the same Image file name
FileStream createFile =
new FileStream(fileName + ".txt", FileMode.CreateNew);
//save the image text in the text file
StreamWriter writeFile = new StreamWriter(createFile);
writeFile.Write(image.Layout.Text);
writeFile.Close();
}
catch (Exception exc)
{
//uncomment the below code to see the expected errors
//MessageBox.Show(exc.Message,
//"OCR Exception",
//MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}