Ejemplo n.º 1
0
        private void InitFormats(Properties.Settings settings)
        {
            DocumentFormat initialFormat = DocumentFormat.Pdf;

            if (!string.IsNullOrEmpty(settings.Format))
            {
                try
                {
                    initialFormat = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), settings.Format);
                }
                catch { }
            }

            if (!string.IsNullOrEmpty(settings.FormatOptionsXml))
            {
                // Set the document writer options from the last one we saved
                try
                {
                    byte[] buffer = Encoding.Unicode.GetBytes(settings.FormatOptionsXml);
                    using (MemoryStream ms = new MemoryStream(buffer))
                    {
                        JobData.OcrEngine.DocumentWriterInstance.LoadOptions(ms);
                    }
                }
                catch
                {
                }
            }

            _documentFormatSelector.SetDocumentWriter(JobData.OcrEngine.DocumentWriterInstance, true);
            _documentFormatSelector.SetOcrEngineType(JobData.OcrEngine.EngineType);
            _documentFormatSelector.SelectedFormat = initialFormat;

            _documentFileNameTextBox.Text = settings.DocumentFileName;
            string extension = DocumentWriter.GetFormatFileExtension(_documentFormatSelector.SelectedFormat);

            if (string.IsNullOrEmpty(_documentFileNameTextBox.Text))
            {
                _documentFileNameTextBox.Text += settings.ImageFileName + "." + extension;
            }
        }
Ejemplo n.º 2
0
        protected override void OnLoad(EventArgs e)
        {
            if (!DesignMode)
            {
                _documentFormatSelector      = new DocumentFormatSelector();
                _documentFormatSelector.Dock = DockStyle.Fill;
                _documentFormatsSelectorPanel.Controls.Add(_documentFormatSelector);
                _documentFormatSelector.BringToFront();

                _documentFormatSelector.SelectedFormatChanged += new EventHandler <EventArgs>(_documentFormatSelector_SelectedFormatChanged);

                Text = Messager.Caption;

                Properties.Settings settings = new Properties.Settings();

                // Show the OCR engine selection dialog to startup the OCR engine
                string engineType = settings.OcrEngineType;

                if (JobData.OcrEngine == null)
                {
                    using (OcrEngineSelectDialog dlg = new OcrEngineSelectDialog(Messager.Caption, engineType, true))
                    {
                        // Use the same RasterCodecs instance in the OCR engine
                        dlg.RasterCodecsInstance = _rasterCodecs;

                        if (dlg.ShowDialog(this) != DialogResult.OK)
                        {
                            // Close the demo
                            DialogResult = DialogResult.Cancel;
                            Close();
                            return;
                        }
                        else
                        {
                            JobData.OcrEngine = dlg.OcrEngine;
                        }
                    }
                }

                Text = string.Format("{0} [{1} Engine]", Messager.Caption, JobData.OcrEngine.EngineType.ToString());

                _imageFileNameTextBox.Text = settings.ImageFileName;
                _imageFirstPageNumber      = settings.FirstPageNumber;
                if (_imageFirstPageNumber < 1)
                {
                    _imageFirstPageNumber = 1;
                }
                _imageLastPageNumber = settings.LastPageNumber;
                if (_imageLastPageNumber < _imageFirstPageNumber)
                {
                    _imageLastPageNumber = -1;
                }

                InitFormats(settings);

                _zonesFileNameTextBox.Text = settings.ZonesFileName;

                try
                {
                    _maximumThreadsPerJobTextBox.Text = settings.MaximumThreadsPerJob.ToString();
                }
                catch
                {
                    _maximumThreadsPerJobTextBox.Text = "0";
                }

                try
                {
                    _maximumPagesBeforeLtdTextBox.Text = settings.MaximumPagesBeforeLtd.ToString();
                }
                catch
                {
                    _maximumPagesBeforeLtdTextBox.Text = "4";
                }

                if (!JobData.OcrEngine.AutoRecognizeManager.IsMultiThreadedSupported)
                {
                    _maximumThreadsPerJobLabel.Visible   = false;
                    _maximumThreadsPerJobTextBox.Visible = false;
                    _maximumThreadsPerJobInfoLabel.Text  = "Multi-threaded is not supported in this engine";
                }

                _preprocessingComboBox.Items.Add("None");
                foreach (OcrAutoPreprocessPageCommand command in Enum.GetValues(typeof(OcrAutoPreprocessPageCommand)))
                {
                    _preprocessingComboBox.Items.Add(command.ToString());
                }

                _preprocessingComboBox.SelectedItem = "None";

                if (!string.IsNullOrEmpty(settings.Preprocessing))
                {
                    if (string.Compare(settings.Preprocessing, "none", true) == 0)
                    {
                        _preprocessingComboBox.SelectedItem = "None";
                    }
                    else
                    {
                        try
                        {
                            OcrAutoPreprocessPageCommand command = (OcrAutoPreprocessPageCommand)Enum.Parse(typeof(OcrAutoPreprocessPageCommand), settings.Preprocessing);
                            _preprocessingComboBox.SelectedItem = command.ToString();
                        }
                        catch { }
                    }
                }

                _continueOnErrorCheckBox.Checked   = settings.ContinueOnRecoverableErrors;
                _enableTraceCheckBox.Checked       = settings.EnableTrace;
                _viewFinalDocumentCheckBox.Checked = settings.ViewFinalDocument;

                UpdateMyControls();

                _loadedOk = true;
            }

            base.OnLoad(e);
        }