Skip to content

ReadAsync issue #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
A41056 opened this issue May 26, 2023 · 0 comments
Open

ReadAsync issue #9

A41056 opened this issue May 26, 2023 · 0 comments

Comments

@A41056
Copy link

A41056 commented May 26, 2023

`string _zPdfFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "File", "hdcc.pdf");

        var _IronOcr = new IronTesseract();
        _IronOcr.Language = OcrLanguage.Vietnamese;

        using (var _Input = new OcrInput())
        {
            _Input.AddPdfPages(_zPdfFilePath, null, null, null);
            string _zPath = "hdcc-searchable.pdf";

            var _t1 = _IronOcr.ReadAsync(_Input, null);
            var _t2 = initializeWebViewAsync();

            Task.WhenAll(_t1, _t2).ContinueWith((_t) =>
            {
                if (Disposing || IsDisposed)
                    return;

                if (_t1.IsCanceled || _t2.IsCanceled)
                    return;
                else if (_t1.Exception != null)
                    MessageBox.Show(_t1.Exception.InnerException.Message);
                else if (_t2.Exception != null)
                    MessageBox.Show(_t2.Exception.InnerException.Message);
                else
                {
                    if (InvokeRequired)
                    {
                        Invoke((MethodInvoker)(() =>
                        {
                            _t1.Result.SaveAsSearchablePdf(_zPath);

                            string _zUrl = "file:///" + Path.GetFullPath(_zPath).Replace('\\', '/');

                            if (webView != null && webView.CoreWebView2 != null)
                            {
                                webView.CoreWebView2.Navigate(_zUrl);
                            }
                        }));
                    }
                    else
                    {
                        _t1.Result.SaveAsSearchablePdf(_zPath);

                        string _zUrl = "file:///" + Path.GetFullPath(_zPath).Replace('\\', '/');

                        if (webView != null && webView.CoreWebView2 != null)
                        {
                            webView.CoreWebView2.Navigate(_zUrl);
                        }
                    }
                }
            });
        }`
        
        I want to convert from an image, scanned pdf file to a searchable pdf. It works fine with Read(), but the main thread will be blocked until the process is finished. So I'm using ReadAsync() to not block the main thread, but I have the error "Recognition of image failed". I don't know why, because the Read() run fine so it can't be an image quality problem. Please help me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant