1

My machine has Office 2010 installed.
I downloaded Sharepoint 2007 MODI for OCR. I am using VS2012.

I get the following error message:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ImageOCR_Modi.exe

Here is a screenshot:

enter image description here

I came to know Office 2010 removed MODI feature, so no support from MS. So can't it be used with Office 2010

Code:

public string CheckFileAndDoOCR(string directoryPath)
{
    string TheTxt = "";
    IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();

    while (files.MoveNext())
    {
        // FileInfo
        FileInfo sudhir = new FileInfo(Convert.ToString(files.Current));

        // Check for JPG File Format
        if (sudhir.Extension == ".jpg" || foo.Extension == ".JPG")
        // or // ImageFormat.Jpeg.ToString()
        {
            // Start OCR Procedure
            TheTxt = DoOCRExact(sudhir.FullName);
            // Create TXT file next to ImageFile
            string txtFileName = sudhir.DirectoryName + "\\" + sudhir.Name.Replace(sudhir.Extension, "") + ".txt";
            FileStream createFile = new FileStream(txtFileName, FileMode.OpenOrCreate);
            // Save the text in to TXT file
            StreamWriter writeFile = new StreamWriter(createFile);
            writeFile.Write(TheTxt);
            // Close
            writeFile.Close();
            createFile.Close();
        }

        try
        { foo.Delete(); }
        catch (Exception ex)
        {

        }
    }
    return TheTxt;
}

public string DoOCRExact(string FullPath)
{
    string txt;

    // OCR Operations...
    MODI.Document md = new MODI.Document(); // Create MODI.Document
    md.Create(FullPath); // Fill MODI.Document with my file
    md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); // OCR();
    // Image from file
    MODI.Image image = (MODI.Image)md.Images[0];
    txt = image.Layout.Text;
    MODI.Word word = image.Layout.Words[0];
    // Close OCR
    word = null;
    image = null;
    md.Close(false);
    md = null;

    // Finalize
    GC.Collect();
    GC.WaitForPendingFinalizers();

    // Return Text
    return txt;
}
  • I have updated code with main question. – Sudhir pradhan Jul 03 '15 at 11:00
  • Welcome to Stack Overflow! I've edited your question - most notably, I added the error message. This makes the problem description more clear, and it helps if people search on this particular error message. Consider catching the Exception and storing it somewhere. By the way, don't "eat" exceptions like you do in the last part of your code; letting an exception disappear this way, may cause critical debugging information to get lost. Meanwhile, good luck with getting this solved! – S.L. Barth is on codidact.com Jul 05 '15 at 16:55

0 Answers0