Exemplo n.º 1
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();
                }
            }
        }
Exemplo n.º 2
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();
                }
            }
        }