How to convert scanned image files to searchable PDF files from web application?

Could not load file or assembly 'Interop.VeryPDF' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Interop.VeryPDF' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I am using OCR2Any SDK/COM, running application in win 32 bit , getting below error

error
Retrieving the COM class factory for component with CLSID {990771DE-4D3A-49B8-803A-C1970E7ACE62} failed due to the following error:
80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). @@
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at ManuOcrApplication.Models.OCRProcess.PreocessOCR(String strInFile, String strOutFile) in

Customer
--------------------------------------------

https://www.verypdf.com/app/ocr-to-any-converter-cmd/try-and-buy.html

Thanks for your message, in order to call "VeryPDF.ocr2anyCom" from your source code, you need register ocr2anyCom.exe into your system with administrator privilege first, for example, you may run a CMD window with "Run As Administrator" menu option first, and then run following command line to register ocr2anyCom.exe into your windows system, "ocr2anyCom.exe" is exist in the "ocr2any_sdk\libs" folder,

ocr2anyCom.exe /regserver

You can also double click "install.vbs" from "libs" folder to register ocr2anyCom.exe into your system, "install.vbs" will use administrator privilege to register ocr2anyCom.exe automatically.

After you register "ocr2anyCom.exe" into your system properly, you can call it from your C#, VB.NET, C++, VB6, etc. program languages, for example,

This is a C# example,
-----------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VeryPDF;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            {
                string strInFile = appPath + "\\test_table_ocr.tif";
                string strOutFile = appPath + "\\_test_out.pdf";
                string strCmd = "-ocrmode 3 -$ XXXX-XXXX-XXXX-XXXX";
                strCmd += " \"" + strInFile + "\" \"" + strOutFile + "\"";

                System.Type VeryPDFType = System.Type.GetTypeFromProgID("VeryPDF.ocr2anyCom");
                VeryPDF.ocr2anyCom VeryPDFCom = (VeryPDF.ocr2anyCom)System.Activator.CreateInstance(VeryPDFType);
                string strReturn = VeryPDFCom.ocr2any(strCmd);
                MessageBox.Show(strReturn);
            }

            {
                string strInFile = appPath + "\\test_table_ocr.tif";
                string strOutFile = appPath + "\\_test_out.rtf";
                string strCmd = "-ocr2 -$ XXXX-XXXX-XXXX-XXXX";
                strCmd += " \"" + strInFile + "\" \"" + strOutFile + "\"";

                System.Type VeryPDFType = System.Type.GetTypeFromProgID("VeryPDF.ocr2anyCom");
                VeryPDF.ocr2anyCom VeryPDFCom = (VeryPDF.ocr2anyCom)System.Activator.CreateInstance(VeryPDFType);
                string strReturn = VeryPDFCom.ocr2any(strCmd);
                MessageBox.Show(strReturn);
            }
        }
    }
}
-----------------------------------------------

This is a VB.NET example,
-----------------------------------------------
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim strFolderDir As String = Application.StartupPath()
        Dim strInFile As String = strFolderDir & "\test_table_ocr.tif"
        Dim strOutFile As String = strFolderDir & "\_test_out.pdf"
        Dim strLicenseKey As String = "-$ XXXX-XXXX-XXXX-XXXX"
        Dim strCmd As String = "-ocrmode 3 " & strLicenseKey & " """ & strInFile & """ """ & strOutFile & """"

        Dim VeryPDFCom As Object = CreateObject("VeryPDF.ocr2anyCom")
        Dim strReturn As String = VeryPDFCom.ocr2any(strCmd)
        MsgBox(strReturn)

        strInFile = strFolderDir & "\test_table_ocr.tif"
        strOutFile = strFolderDir & "\_test_out.rtf"
        strLicenseKey = "-$ XXXX-XXXX-XXXX-XXXX"
        strCmd = "-ocr2 " & strLicenseKey & " """ & strInFile & """ """ & strOutFile & """"
        strReturn = VeryPDFCom.ocr2any(strCmd)
        MsgBox(strReturn)

    End Sub
End Class
-----------------------------------------------

This is a VB6 example,
-----------------------------------------------
Private Sub Command1_Click()
    strFolderDir = App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "")
    strInFile = strFolderDir & "\test_table_ocr.tif"
    strOutFile = strFolderDir & "\_test_out.pdf"
    strLicenseKey = "-$ XXXX-XXXX-XXXX-XXXX"
    strCmd = "-ocrmode 3 " & strLicenseKey & " """ & strInFile & """ """ & strOutFile & """"
   
    Set VeryPDFCom = CreateObject("VeryPDF.ocr2anyCom")
    strReturn = VeryPDFCom.ocr2any(strCmd)
    MsgBox strReturn
   
   
    strInFile = strFolderDir & "\test_table_ocr.tif"
    strOutFile = strFolderDir & "\_test_out.rtf"
    strLicenseKey = "-$ XXXX-XXXX-XXXX-XXXX"
    strCmd = "-ocr2 " & strLicenseKey & " """ & strInFile & """ """ & strOutFile & """"
   
    Set VeryPDFCom = CreateObject("VeryPDF.ocr2anyCom")
    strReturn = VeryPDFCom.ocr2any(strCmd)
    MsgBox strReturn
   
End Sub
-----------------------------------------------

btw, I just noticed a "Access is denied" error in your log message, this error is caused by permission restrictions, your web application hasn't permissions to access to "VeryPDF.ocr2anyCom" COM interface, you need to give full control permissions to "VeryPDF.ocr2anyCom" in your system, please refer to following steps,

1. "Start" -> "Run" -> type in "dcomcnfg" on 32bit system or "MMC comexp.msc /32" on 64bit system,

In the Component Services Window, expand the tree item:

Console Root / Component Services / Computers / My computer / DCOM Config

Right click the "VeryPDF.ocr2anyCom" entry and select "Properties":

2. In the 'COM Properties' dialog, select the the 'Security' tab,

3. In the 'Access Permissions' area, select "Customize" and click Edit.

4. Ensure that "Everyone" is present in the list of names. If not, add it by clicking the Add button, typing "Everyone" and give it all permissions, and clicking OK.

5. Make sure "Everyone" has the Access Permission 'Allow' check box ticked.

Click OK to return to the 'properties' window.

You need give "Full Control Permission" to "Everyone" to "Launch and Activation Permissions", "Access Permissions" and "Configuration Permissions" three items.

image

6. Click "Identity" tab. Check the "This user" checkbox, press "Browse" and specify the Administrator account, enter and re-enter the Administrator password, OR simple choose "The interactive user." option.

7. Click "OK" to save it,

8. Add "Everyone" user account to the folder where the ocr2anyCom.exe inside, and assign "Full Control" permission to "Everyone" user account, if you don't give enough permission to this folder, ASP, PHP, C#, VB.NET, ASP.NET etc. web applications will be denied to access to this folder,

9. OK, you can call "VeryPDF.ocr2anyCom" from ASP, PHP, C#, VB.NET, ASP.NET, VBScript, JavaScript, Delphi, etc. program languages without any restrictions now.

Please look at following web page for more information about how to set permissions in dcomcnfg application, although this web page is wrote for "VeryPDFCom.RunCmd", but the steps are same for "VeryPDF.ocr2anyCom",

https://www.verydoc.com/blog/verydoc-release-notes-verydoc-releases-an-exe-com-of-verypdfcomruncmd-exe-today-verypdf-exe-com-does-allow-you-to-call-ms-office-and-any-exe-application-from-asp-php-c-net-etc-program-languag.html

VeryPDF

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!