コード例 #1
0
        private void SaveDocument(string documentFileName)
        {
            // Update the characters from what we have so far
            // The word is remove now from the OCR results
            _ocrPage.SetRecognizedCharacters(_ocrPageCharacters);

            // Save this document as PDF

            // Setup the arguments for the callback
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("documentFileName", documentFileName);
            args.Add("viewDocument", _preferencesViewSavedDocumentToolStripMenuItem.Checked);

            // Call the process dialog
            try
            {
                bool allowProgress = _preferencesUseCallbacksToolStripMenuItem.Checked;
                using (OcrProgressDialog dlg = new OcrProgressDialog(allowProgress, "Saving Document", new OcrProgressDialog.ProcessDelegate(DoSaveDocument), args))
                {
                    dlg.ShowDialog(this);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UpdateUIState();
            }
        }
コード例 #2
0
        private void OpenDocument(string documentFileName)
        {
            // Create a new document, add the page to it and recognize it
            // If all the above is OK, then use it

            // Setup the arguments for the callback
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("documentFileName", documentFileName);

            // Call the process dialog
            try
            {
                bool allowProgress = _preferencesUseCallbacksToolStripMenuItem.Checked;
                using (OcrProgressDialog dlg = new OcrProgressDialog(allowProgress, "Loading and Recognizing Document", new OcrProgressDialog.ProcessDelegate(DoLoadAndRecognizeDocument), args))
                {
                    dlg.ShowDialog(this);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UpdateUIState();
            }
        }
コード例 #3
0
        private void DoSaveDocument(OcrProgressDialog dlg, Dictionary <string, object> args)
        {
            // Perform load and recognize here

            OcrProgressCallback callback = dlg.OcrProgressCallback;

            try
            {
                string documentFileName = args["documentFileName"] as string;
                bool   viewDocument     = (bool)args["viewDocument"];

                if (!dlg.IsCanceled)
                {
                    // If we are not using a progress bar, update the description text
                    if (callback == null)
                    {
                        dlg.UpdateDescription("Saving the document ...");
                    }

                    PdfDocumentOptions pdfOptions = _ocrDocument.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
                    pdfOptions.Producer = "LEAD Technologies, Inc.";
                    pdfOptions.Creator  = "LEADTOOLS PDFWriter";
                    _ocrDocument.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions);
                    _ocrDocument.Save(documentFileName, DocumentFormat.Pdf, callback);
                }

                // If it has not been canceled, show the final document (if applicable)
                if (!dlg.IsCanceled && viewDocument)
                {
                    Process.Start(documentFileName);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                if (callback == null)
                {
                    dlg.EndOperation();
                }
            }
        }
コード例 #4
0
        private void DoLoadAndRecognizeDocument(OcrProgressDialog dlg, Dictionary <string, object> args)
        {
            // Perform load and recognize here

            OcrProgressCallback callback    = dlg.OcrProgressCallback;
            IOcrDocument        ocrDocument = null;

            try
            {
                string documentFileName = args["documentFileName"] as string;

                ocrDocument = _ocrEngine.DocumentManager.CreateDocument("", OcrCreateDocumentOptions.InMemory);

                IOcrPage ocrPage = null;

                if (!dlg.IsCanceled)
                {
                    // If we are not using a progress bar, update the description text
                    if (callback == null)
                    {
                        dlg.UpdateDescription("Loading the document (first page only)...");
                    }

                    ocrPage = ocrDocument.Pages.AddPage(documentFileName, callback);
                }

                if (!dlg.IsCanceled)
                {
                    // If we are not using a progress bar, update the description text
                    if (callback == null)
                    {
                        dlg.UpdateDescription("Recognizing the page(s) of the document...");
                    }

                    ocrPage.Recognize(callback);
                }

                if (!dlg.IsCanceled)
                {
                    // We did not cancel, use this document
                    SetDocument(ocrDocument, documentFileName);
                    ocrDocument = null;
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                if (callback == null)
                {
                    dlg.EndOperation();
                }

                // Clean up
                if (ocrDocument != null)
                {
                    ocrDocument.Dispose();
                }
            }
        }