Пример #1
0
        private string GetFileExtension(DocumentFormat format)
        {
            string extension;

            if (format == DocumentFormat.User)
            {
                MyEngineFormat      mef = _userFormatNameComboBox.SelectedItem as MyEngineFormat;
                IOcrDocumentManager ocrDocumentManager = _engine.DocumentManager;
                extension = ocrDocumentManager.GetEngineFormatFileExtension(mef.Format);
            }
            else
            {
                extension = DocumentWriter.GetFormatFileExtension(format);
            }

            return(extension);
        }
Пример #2
0
        private void _documentFileNameBrowseButton_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Title = "Select output document file name";
                DocumentFormat format     = _documentFormatSelector.SelectedFormat;
                string         extension  = DocumentWriter.GetFormatFileExtension(format);
                string         formatName = DocumentWriter.GetFormatFriendlyName(format);
                dlg.Filter     = string.Format("{0} (*.{1})|*.{1}|All Files|*.*", formatName, extension);
                dlg.DefaultExt = extension;
                dlg.FileName   = Path.GetFileName(_documentFileNameTextBox.Text);

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    _documentFileNameTextBox.Text = dlg.FileName;
                }
            }
        }
Пример #3
0
        private void _ldFileNameBrowseButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                string extension    = DocumentWriter.GetFormatFileExtension(DocumentFormat.Ltd);
                string friendlyName = DocumentWriter.GetFormatFriendlyName(DocumentFormat.Ltd);
                dlg.Filter     = string.Format("{0} (*.{1})|*.{1}|All Files (*.*)|*.*", friendlyName, extension);
                dlg.DefaultExt = extension;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    _ldFileNameTextBox.Text = dlg.FileName;

                    if (_outputFileNameTextBox.Text.Trim().Length == 0)
                    {
                        UpdateOutputFileName();
                    }
                }
            }
        }
Пример #4
0
        private void _outputFileNameBrowseButton_Click(object sender, EventArgs e)
        {
            // Show the save file dialog

            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                // Get the selected format name and extension
                MyFormat mf = _formatComboBox.SelectedItem as MyFormat;

                string extension = DocumentWriter.GetFormatFileExtension(mf.Format);

                dlg.Filter     = string.Format("{0} (*.{1})|*.{1}|All Files (*.*)|*.*", mf.FriendlyName, extension);
                dlg.DefaultExt = extension;

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    _outputFileNameTextBox.Text = dlg.FileName;
                }
            }
        }
Пример #5
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;
            }
        }
Пример #6
0
        private void _fileSaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Show the save file dialog
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                string friendlyName = DocumentWriter.GetFormatFriendlyName(DocumentFormat.Pdf);
                string extension    = DocumentWriter.GetFormatFileExtension(DocumentFormat.Pdf);

                dlg.Filter = string.Format("{0} Documents (*.{1})|*.{1}|All Files|*.*", friendlyName, extension);

                if (!string.IsNullOrEmpty(_lastDocumentFile))
                {
                    dlg.FileName = Path.ChangeExtension(_lastDocumentFile, extension);
                }

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    SaveDocument(dlg.FileName);
                }
            }
        }
Пример #7
0
        private void _imageFileNameBrowseButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Title  = "Select image file to OCR";
                dlg.Filter = "All Files|*.*";
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    _imageFileNameTextBox.Text = dlg.FileName;
                    if (!string.IsNullOrEmpty(_documentFileNameTextBox.Text))
                    {
                        char[] trimChars = { '\\' };
                        _documentFileNameTextBox.Text = ((string.IsNullOrEmpty(Path.GetDirectoryName(_documentFileNameTextBox.Text))) ? Path.GetDirectoryName(dlg.FileName) : Path.GetDirectoryName(_documentFileNameTextBox.Text).TrimEnd(trimChars)) + "\\" + Path.GetFileName(dlg.FileName);
                    }
                    else
                    {
                        _documentFileNameTextBox.Text = dlg.FileName;
                    }

                    _documentFileNameTextBox.Text += "." + DocumentWriter.GetFormatFileExtension(_documentFormatSelector.SelectedFormat);
                }
            }
        }
Пример #8
0
        private void _documentFormatSelector_SelectedFormatChanged(object sender, EventArgs e)
        {
            // Change the Document Image file extension when the document format is changed.
            DocumentFormat format    = _documentFormatSelector.SelectedFormat;
            string         extension = DocumentWriter.GetFormatFileExtension(format);

            _documentFileNameTextBox.Text = Path.ChangeExtension(_documentFileNameTextBox.Text, extension);

            DocumentOptions options = JobData.OcrEngine.DocumentWriterInstance.GetOptions(_documentFormatSelector.SelectedFormat);

            _documentFormatSelector.TotalPages = JobData.LastPageNumber - JobData.FirstPageNumber;
            switch (_documentFormatSelector.SelectedFormat)
            {
            case DocumentFormat.Xps:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Doc:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Docx:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Rtf:
                _documentFormatSelector.FormatHasOptions = true;
                break;

#if LEADTOOLS_V17_OR_LATER
            case DocumentFormat.Xls:
                _documentFormatSelector.FormatHasOptions = false;
                break;
#endif

#if LEADTOOLS_V19_OR_LATER
            case DocumentFormat.AltoXml:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Pub:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Mob:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Svg:
                _documentFormatSelector.FormatHasOptions = false;
                break;
#endif // #if LEADTOOLS_V19_OR_LATER

            default:
                _documentFormatSelector.FormatHasOptions = true;
                break;
            }

            if (options != null)
            {
                JobData.OcrEngine.DocumentWriterInstance.SetOptions(_documentFormatSelector.SelectedFormat, options);
            }
        }
Пример #9
0
        public void SetDocumentWriter(DocumentWriter docWriter, bool showLtdFormat)
        {
            _documentWriter = docWriter;

            // This is the order of importance, show these first then the rest as they come along
            DocumentFormat[] importantFormats =
            {
                DocumentFormat.Pdf,
                DocumentFormat.Docx,
                DocumentFormat.Rtf,
                DocumentFormat.Text,
                DocumentFormat.Doc,
                DocumentFormat.Xls,
                DocumentFormat.Html
            };

            List <DocumentFormat> formatsToAdd = new List <DocumentFormat>();

            Array a = Enum.GetValues(typeof(DocumentFormat));
            List <DocumentFormat> allFormats = new List <DocumentFormat>();

            foreach (DocumentFormat format in a)
            {
                allFormats.Add(format);
            }

            // Add important once first:
            foreach (DocumentFormat format in importantFormats)
            {
                formatsToAdd.Add(format);
                allFormats.Remove(format);
            }

            // Add rest
            formatsToAdd.AddRange(allFormats);

            // Add rest
            foreach (DocumentFormat format in formatsToAdd)
            {
                bool addItem = true;

                if (format == DocumentFormat.User)
                {
                    addItem = false;
                }
                else if (format == DocumentFormat.Ltd && !showLtdFormat)
                {
                    addItem = false;
                }

                if (addItem)
                {
                    string             name = string.Format("{0} ({1})", DocumentWriter.GetFormatFriendlyName(format), DocumentWriter.GetFormatFileExtension(format).ToUpperInvariant());
                    DocumentFormatItem item = new DocumentFormatItem(format, name);
                    _formatComboBox.Items.Add(item);

                    if (format == DocumentFormat.Pdf)
                    {
                        _formatComboBox.SelectedItem = item;
                    }
                }
            }

            if (_formatComboBox.SelectedIndex == -1 && _formatComboBox.Items.Count > 0)
            {
                _formatComboBox.SelectedIndex = 0;
            }

            PdfDocumentOptions pdfOptions = _documentWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

            if (string.IsNullOrEmpty(pdfOptions.Creator))
            {
                pdfOptions.Creator = "LEADTOOLS PDFWriter";
            }
            if (string.IsNullOrEmpty(pdfOptions.Producer))
            {
                pdfOptions.Producer = "LEAD Technologies, Inc.";
            }
            _documentWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);
        }
Пример #10
0
        private void _documentFormatSelector_SelectedFormatChanged(object sender, EventArgs e)
        {
            // Update the file name of the document with the correct extension
            string documentFileName = _tbFinalDocumentFileName.Text.Trim();

            if (!string.IsNullOrEmpty(documentFileName))
            {
                DocumentFormat format    = _documentFormatSelector.SelectedFormat;
                string         extension = DocumentWriter.GetFormatFileExtension(format);
                documentFileName = Path.ChangeExtension(documentFileName, extension);
                _tbFinalDocumentFileName.Text = documentFileName;
            }

            DocumentOptions options = _ocrEngine.DocumentWriterInstance.GetOptions(_documentFormatSelector.SelectedFormat);

            _documentFormatSelector.TotalPages = 1;

            switch (_documentFormatSelector.SelectedFormat)
            {
            case DocumentFormat.Xps:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Doc:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Docx:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Rtf:
                _documentFormatSelector.FormatHasOptions = true;
                break;

#if LEADTOOLS_V17_OR_LATER
            case DocumentFormat.Xls:
                _documentFormatSelector.FormatHasOptions = false;
                break;
#endif // #if LEADTOOLS_V17_OR_LATER

#if LEADTOOLS_V19_OR_LATER
            case DocumentFormat.AltoXml:
                _documentFormatSelector.FormatHasOptions = true;
                break;

            case DocumentFormat.Pub:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Mob:
                _documentFormatSelector.FormatHasOptions = false;
                break;

            case DocumentFormat.Svg:
                _documentFormatSelector.FormatHasOptions = false;
                break;
#endif // #if LEADTOOLS_V19_OR_LATER

            default:
                _documentFormatSelector.FormatHasOptions = true;
                break;
            }

            if (options != null)
            {
                _ocrEngine.DocumentWriterInstance.SetOptions(_documentFormatSelector.SelectedFormat, options);
            }
        }
        public DocumentFormatOptionsDialog(OcrEngineType ocrEngineType, DocumentWriter docWriter, DocumentFormat format, int totalPages)
        {
            InitializeComponent();

            _ocrEngineType  = ocrEngineType;
            _documentWriter = docWriter;
            _format         = format;
            _totalPages     = totalPages;

            _optionsTabControl.TabPages.Clear();

            switch (_format)
            {
            case DocumentFormat.Pdf:
                // Update the PDF options page
            {
                _optionsTabControl.TabPages.Add(_pdfOptionsTabPage);

                PdfDocumentOptions pdfOptions = _documentWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

                // Clone it in case we change it in the Advance PDF options dialog
                _pdfOptions = pdfOptions.Clone() as PdfDocumentOptions;

                Array a = Enum.GetValues(typeof(PdfDocumentType));
                foreach (PdfDocumentType i in a)
                {
                    // PDFA does NOT support Arabic characters so we are not adding it in case of Arabic OCR engine.
                    if (ocrEngineType == OcrEngineType.OmniPageArabic && i == PdfDocumentType.PdfA)
                    {
                        continue;
                    }

                    _pdfDocumentTypeComboBox.Items.Add(i);
                }
                _pdfDocumentTypeComboBox.SelectedItem = pdfOptions.DocumentType;

                _pdfImageOverTextCheckBox.Checked = pdfOptions.ImageOverText;
                _pdfLinearizedCheckBox.Checked    = pdfOptions.Linearized;
            }
            break;

            case DocumentFormat.Doc:
                // Update the DOC options page
            {
                _optionsTabControl.TabPages.Add(_docOptionsTabPage);
                DocDocumentOptions docOptions = _documentWriter.GetOptions(DocumentFormat.Doc) as DocDocumentOptions;
                _docFramedCheckBox.Checked = (docOptions.TextMode == DocumentTextMode.Framed) ? true : false;
            }
            break;

            case DocumentFormat.Docx:
                // Update the DOCX options page
            {
                _optionsTabControl.TabPages.Add(_docxOptionsTabPage);
                DocxDocumentOptions docxOptions = _documentWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;
                _docxFramedCheckBox.Checked = (docxOptions.TextMode == DocumentTextMode.Framed) ? true : false;
            }
            break;

            case DocumentFormat.Rtf:
                // Update the RTF options page
            {
                _optionsTabControl.TabPages.Add(_rtfOptionsTabPage);
                RtfDocumentOptions rtfOptions = _documentWriter.GetOptions(DocumentFormat.Rtf) as RtfDocumentOptions;
                _rtfFramedCheckBox.Checked = (rtfOptions.TextMode == DocumentTextMode.Framed) ? true : false;
            }
            break;

            case DocumentFormat.Html:
                // Update the HTML options page
            {
                _optionsTabControl.TabPages.Add(_htmlOptionsTabPage);

                HtmlDocumentOptions htmlOptions = _documentWriter.GetOptions(DocumentFormat.Html) as HtmlDocumentOptions;

                Array a = Enum.GetValues(typeof(DocumentFontEmbedMode));
                foreach (DocumentFontEmbedMode i in a)
                {
                    _htmlEmbedFontModeComboBox.Items.Add(i);
                }
                _htmlEmbedFontModeComboBox.SelectedItem = htmlOptions.FontEmbedMode;

                _htmlUseBackgroundColorCheckBox.Checked = htmlOptions.UseBackgroundColor;

                _htmlBackgroundColorValueLabel.BackColor = Leadtools.Demos.Converters.ToGdiPlusColor(htmlOptions.BackgroundColor);

                _htmlBackgroundColorLabel.Enabled      = _htmlUseBackgroundColorCheckBox.Checked;
                _htmlBackgroundColorValueLabel.Enabled = _htmlUseBackgroundColorCheckBox.Checked;
                _htmlBackgroundColorButton.Enabled     = _htmlUseBackgroundColorCheckBox.Checked;
            }
            break;

            case DocumentFormat.Text:
                // Update the TEXT options page
            {
                _optionsTabControl.TabPages.Add(_textOptionsTabPage);

                TextDocumentOptions textOptions = _documentWriter.GetOptions(DocumentFormat.Text) as TextDocumentOptions;

                Array a = Enum.GetValues(typeof(TextDocumentType));
                foreach (TextDocumentType i in a)
                {
                    if (i == TextDocumentType.Ansi && ocrEngineType == OcrEngineType.OmniPageArabic)
                    {
                        continue;
                    }

                    _textDocumentTypeComboBox.Items.Add(i);
                }
                _textDocumentTypeComboBox.SelectedItem = textOptions.DocumentType;

                _textAddPageNumberCheckBox.Checked = textOptions.AddPageNumber;
                _textAddPageBreakCheckBox.Checked  = textOptions.AddPageBreak;
                _textFormattedCheckBox.Checked     = textOptions.Formatted;
            }
            break;

            case DocumentFormat.AltoXml:
                // Update the ALTOXML options page
            {
                _optionsTabControl.TabPages.Add(_altoXmlOptionsTabPage);
                AltoXmlDocumentOptions altoXmlOptions = _documentWriter.GetOptions(DocumentFormat.AltoXml) as AltoXmlDocumentOptions;

                Array a = Enum.GetValues(typeof(AltoXmlMeasurementUnit));
                foreach (AltoXmlMeasurementUnit i in a)
                {
                    _altoXmlMeasurementUnitComboBox.Items.Add(i);
                }
                _altoXmlMeasurementUnitComboBox.SelectedItem = altoXmlOptions.MeasurementUnit;

                _altoXmlFileNameTextBox.Text               = altoXmlOptions.FileName;
                _altoXmlSoftwareCreatorTextBox.Text        = altoXmlOptions.SoftwareCreator;
                _altoXmlSoftwareNameTextBox.Text           = altoXmlOptions.SoftwareName;
                _altoXmlApplicationDescriptionTextBox.Text = altoXmlOptions.ApplicationDescription;
                _altoXmlFormattedCheckBox.Checked          = altoXmlOptions.Formatted;
                _altoXmlIndentationTextBox.Text            = altoXmlOptions.Indentation;
                _altoXmlSortCheckBox.Checked               = altoXmlOptions.Sort;
                _altoXmlPlainTextCheckBox.Checked          = altoXmlOptions.PlainText;
                _altoXmlShowGlyphInfoCheckBox.Checked      = altoXmlOptions.ShowGlyphInfo;
                _altoXmlShowGlyphVariantsCheckBox.Checked  = altoXmlOptions.ShowGlyphVariants;
            }
            break;

            case DocumentFormat.Ltd:
            {
                _optionsTabControl.TabPages.Add(_ldOptionsTabPage);
            }
            break;

            case DocumentFormat.Emf:
            {
                _optionsTabControl.TabPages.Add(_emfOptionsTabPage);
            }
            break;

            default:
            {
                _optionsTabControl.TabPages.Add(_emptyOptionsTabPage);
                _emptyOptionsTabPage.Text = string.Format("{0} Options", DocumentWriter.GetFormatFileExtension(_format).ToUpperInvariant());
            }
            break;
            }

            Text = DocumentWriter.GetFormatFriendlyName(_format) + " " + DemosGlobalization.GetResxString(GetType(), "Resx_Options");

            UpdateUIState();
        }
Пример #12
0
        private void ThreadProc(object stateInfo)
        {
            WorkItemData data                = (WorkItemData)stateInfo;
            IOcrEngine   ocrEngine           = null;
            bool         passedCriticalStage = false;

            try
            {
                // See if we have canceled
                lock (_abortedLockObject)
                {
                    if (_aborted)
                    {
                        return;
                    }
                }

                string destinationFile = Path.Combine(data.DestinationDirectory, Path.GetFileName(data.SourceFile));

                ocrEngine = data.OcrEngine;

                lock (_abortedLockObject)
                {
                    if (_aborted)
                    {
                        return;
                    }
                }

                // Convert this image file to a document
                string extension = DocumentWriter.GetFormatFileExtension(data.Format);
                destinationFile = string.Concat(destinationFile, ".", extension);
                if (data.Format == DocumentFormat.Ltd && File.Exists(destinationFile))
                {
                    File.Delete(destinationFile);
                }

                string sourceFile = Path.GetFileName(data.SourceFile);

                try
                {
                    // Create a document and add the pages
                    using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(null, OcrCreateDocumentOptions.AutoDeleteFile))
                    {
                        // Get the image number of pages
                        int imagePageCount;

                        RasterCodecs codecs = ocrDocument.RasterCodecsInstance;

                        using (CodecsImageInfo imageInfo = codecs.GetInformation(data.SourceFile, true))
                        {
                            long maximumMemorySize            = 42187;
                            IOcrSettingManager settingManager = ocrEngine.SettingManager;

                            // Get the maximum size of the bitmap from the setting
                            if (settingManager.IsSettingNameSupported("Recognition.MaximumPageConventionalMemorySize"))
                            {
                                int maximumConventionalMemorySize = settingManager.GetIntegerValue("Recognition.MaximumPageConventionalMemorySize");
                                maximumMemorySize = (long)maximumConventionalMemorySize * 1024;
                            }

                            SetRecommendedLoadingOptions(codecs, imageInfo, maximumMemorySize);

                            imagePageCount = imageInfo.TotalPages;
                        }

                        // Set the DocumentWriter options
                        using (MemoryStream ms = new MemoryStream(data.DocumentWriterOptions))
                        {
                            ocrDocument.DocumentWriterInstance.LoadOptions(ms);
                        }

                        passedCriticalStage = true;

                        //recognize and add pages
                        for (int pageNumber = 1; pageNumber <= imagePageCount; pageNumber++)
                        {
                            lock (_abortedLockObject)
                            {
                                if (_aborted)
                                {
                                    return;
                                }
                            }

                            var image = codecs.Load(data.SourceFile, pageNumber);

                            using (var ocrPage = ocrEngine.CreatePage(image, OcrImageSharingMode.AutoDispose))
                            {
                                ocrPage.Recognize(null);
                                ocrDocument.Pages.Add(ocrPage);
                            }
                        }

                        // Save
                        ocrDocument.Save(destinationFile, data.Format, null);
                    }
                }
                finally
                {
                }

                OnSuccess(destinationFile);
            }
            catch (Exception ex)
            {
                string message;

                if (passedCriticalStage && data.FirstTry)
                {
                    message = string.Format("Error '{0}' while converting file '{1}' (first time, quarantined)", ex.Message, data.SourceFile);
                    AddToQuarantine(data.SourceFile);
                }
                else if (passedCriticalStage && !data.FirstTry)
                {
                    message = string.Format("Error '{0}' while converting file '{1}' (quarantined error)", ex.Message, data.SourceFile);
                }
                else
                {
                    message = string.Format("Error '{0}' while converting file '{1}'", ex.Message, data.SourceFile);
                }

                OnError(message);
            }
            finally
            {
                if (ocrEngine != null && ocrEngine != data.OcrEngine)
                {
                    ocrEngine.Dispose();
                }

                if (Interlocked.Decrement(ref _workItemCount) == 0)
                {
                    _batchFinishedEvent.Set();
                }
            }
        }
Пример #13
0
        public ConvertLdDialog(IOcrDocument ocrDocument, DocumentWriter docWriter, DocumentFormat initialFormat, string initialLdFileName, bool viewDocument)
        {
            InitializeComponent();

            _ocrDocument = ocrDocument;
            _docWriter   = docWriter;

            // Get the formats
            // This is the order of importance, show these first then the rest as they come along
            DocumentFormat[] importantFormats =
            {
                DocumentFormat.Pdf,
                DocumentFormat.Docx,
                DocumentFormat.Rtf,
                DocumentFormat.Text,
                DocumentFormat.Doc,
                DocumentFormat.Xls,
                DocumentFormat.Html
            };

            List <DocumentFormat> formatsToAdd = new List <DocumentFormat>();

            Array temp = Enum.GetValues(typeof(DocumentFormat));
            List <DocumentFormat> allFormats = new List <DocumentFormat>();

            foreach (DocumentFormat format in temp)
            {
                allFormats.Add(format);
            }

            // Add important once first:
            foreach (DocumentFormat format in importantFormats)
            {
                formatsToAdd.Add(format);
                allFormats.Remove(format);
            }

            // Add rest
            formatsToAdd.AddRange(allFormats);

            MyFormat pdfFormat = null;

            foreach (DocumentFormat format in formatsToAdd)
            {
                bool addFormat = true;

                // If this is the "User" or Engines format, only add it if the OCR engine supports them
                if (format == DocumentFormat.User || format == DocumentFormat.Ltd)
                {
                    addFormat = false;
                }

                if (addFormat)
                {
                    string friendlyName = DocumentWriter.GetFormatFriendlyName(format);
                    string extension    = DocumentWriter.GetFormatFileExtension(format).ToUpper();

                    MyFormat mf = new MyFormat(format, friendlyName, extension);

                    _formatComboBox.Items.Add(mf);

                    if (mf.Format == initialFormat)
                    {
                        _formatComboBox.SelectedItem = mf;
                    }
                    else if (mf.Format == DocumentFormat.Pdf)
                    {
                        pdfFormat = mf;
                    }

                    switch (format)
                    {
                    case DocumentFormat.Pdf:
                        // Update the PDF options page
                    {
                        PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

                        // Clone it in case we change it in the Advance PDF options dialog
                        _pdfOptions = pdfOptions.Clone() as PdfDocumentOptions;

                        Array a = Enum.GetValues(typeof(PdfDocumentType));
                        foreach (PdfDocumentType i in a)
                        {
                            _pdfDocumentTypeComboBox.Items.Add(i);
                        }
                        _pdfDocumentTypeComboBox.SelectedItem = _pdfOptions.DocumentType;

                        _pdfImageOverTextCheckBox.Checked = _pdfOptions.ImageOverText;
                        _pdfLinearizedCheckBox.Checked    = _pdfOptions.Linearized;

                        if (string.IsNullOrEmpty(_pdfOptions.Creator))
                        {
                            _pdfOptions.Creator = "LEADTOOLS PDFWriter";
                        }
                        if (string.IsNullOrEmpty(_pdfOptions.Producer))
                        {
                            _pdfOptions.Producer = "LEAD Technologies, Inc.";
                        }
                    }
                    break;

                    case DocumentFormat.Doc:
                        // Update the DOC options page
                    {
                        DocDocumentOptions docOptions = docWriter.GetOptions(DocumentFormat.Doc) as DocDocumentOptions;
                        _cbFramedDoc.Checked = (docOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Docx:
                        // Update the DOCX options page
                    {
                        DocxDocumentOptions docxOptions = docWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;
                        _cbFramedDocX.Checked = (docxOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Rtf:
                        // Update the RTF options page
                    {
                        RtfDocumentOptions rtfOptions = docWriter.GetOptions(DocumentFormat.Rtf) as RtfDocumentOptions;
                        _cbFramedRtf.Checked = (rtfOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Html:
                        // Update the HTML options page
                    {
                        HtmlDocumentOptions htmlOptions = docWriter.GetOptions(DocumentFormat.Html) as HtmlDocumentOptions;

                        Array a = Enum.GetValues(typeof(DocumentFontEmbedMode));
                        foreach (DocumentFontEmbedMode i in a)
                        {
                            _htmlEmbedFontModeComboBox.Items.Add(i);
                        }
                        _htmlEmbedFontModeComboBox.SelectedItem = htmlOptions.FontEmbedMode;

                        _htmlUseBackgroundColorCheckBox.Checked = htmlOptions.UseBackgroundColor;

                        _htmlBackgroundColorValueLabel.BackColor = MainForm.ConvertColor(htmlOptions.BackgroundColor);

                        _htmlBackgroundColorLabel.Enabled      = _htmlUseBackgroundColorCheckBox.Checked;
                        _htmlBackgroundColorValueLabel.Enabled = _htmlUseBackgroundColorCheckBox.Checked;
                        _htmlBackgroundColorButton.Enabled     = _htmlUseBackgroundColorCheckBox.Checked;
                    }
                    break;

                    case DocumentFormat.Text:
                        // Update the TEXT options page
                    {
                        TextDocumentOptions textOptions = docWriter.GetOptions(DocumentFormat.Text) as TextDocumentOptions;

                        Array a = Enum.GetValues(typeof(TextDocumentType));
                        foreach (TextDocumentType i in a)
                        {
                            _textDocumentTypeComboBox.Items.Add(i);
                        }
                        _textDocumentTypeComboBox.SelectedItem = textOptions.DocumentType;

                        _textAddPageNumberCheckBox.Checked = textOptions.AddPageNumber;
                        _textAddPageBreakCheckBox.Checked  = textOptions.AddPageBreak;
                        _textFormattedCheckBox.Checked     = textOptions.Formatted;
                    }
                    break;

                    case DocumentFormat.AltoXml:
                        // Update the ALTOXML options page
                    {
                        AltoXmlDocumentOptions altoXmlOptions = docWriter.GetOptions(DocumentFormat.AltoXml) as AltoXmlDocumentOptions;
                        _altoXmlFileNameTextBox.Text               = altoXmlOptions.FileName;
                        _altoXmlSoftwareCreatorTextBox.Text        = altoXmlOptions.SoftwareCreator;
                        _altoXmlSoftwareNameTextBox.Text           = altoXmlOptions.SoftwareName;
                        _altoXmlApplicationDescriptionTextBox.Text = altoXmlOptions.ApplicationDescription;
                        _altoXmlFormattedCheckBox.Checked          = altoXmlOptions.Formatted;
                        _altoXmlIndentationTextBox.Text            = altoXmlOptions.Indentation;
                        _altoXmlSort.Checked              = altoXmlOptions.Sort;
                        _altoXmlPlainText.Checked         = altoXmlOptions.PlainText;
                        _altoXmlShowGlyphInfo.Checked     = altoXmlOptions.ShowGlyphInfo;
                        _altoXmlShowGlyphVariants.Checked = altoXmlOptions.ShowGlyphVariants;

                        Array a = Enum.GetValues(typeof(AltoXmlMeasurementUnit));
                        foreach (AltoXmlMeasurementUnit i in a)
                        {
                            _altoXmlMeasurementUnit.Items.Add(i);
                        }
                        _altoXmlMeasurementUnit.SelectedItem = altoXmlOptions.MeasurementUnit;
                    }
                    break;

                    case DocumentFormat.Emf:
                    case DocumentFormat.Xls:
                    case DocumentFormat.Pub:
                    case DocumentFormat.Mob:
                    case DocumentFormat.Svg:
                    default:
                        // These formats have no options
                        break;
                    }
                }
            }

            // Remove all the tab pages
            _optionsTabControl.TabPages.Clear();

            // If no format is selected, default to PDF
            if (_formatComboBox.SelectedIndex == -1)
            {
                if (pdfFormat != null)
                {
                    _formatComboBox.SelectedItem = pdfFormat;
                }
                else
                {
                    _formatComboBox.SelectedIndex = -1;
                }
            }

            _viewDocumentCheckBox.Checked = viewDocument;

            _formatComboBox_SelectedIndexChanged(this, EventArgs.Empty);

            if (!string.IsNullOrEmpty(initialLdFileName))
            {
                _ldFileNameTextBox.Text = initialLdFileName;
                UpdateOutputFileName();
            }

            UpdateUIState();
        }
Пример #14
0
        private void _formatComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyFormat mf = _formatComboBox.SelectedItem as MyFormat;

            // Update the extension of the output file name
            // Update the current format options tab page
            string fileName = _outputFileNameTextBox.Text;

            if (!string.IsNullOrEmpty(fileName))
            {
                string extension = DocumentWriter.GetFormatFileExtension(mf.Format);
                _outputFileNameTextBox.Text = Path.ChangeExtension(fileName, extension);
            }

            // Show only the options page corresponding to this format
            if (_optionsTabControl.TabPages.Count > 0)
            {
                _optionsTabControl.TabPages.Clear();
            }

            switch (mf.Format)
            {
            case DocumentFormat.Emf:
                _optionsTabControl.TabPages.Add(_emfOptionsTabPage);
                break;

            case DocumentFormat.Pdf:
                _optionsTabControl.TabPages.Add(_pdfOptionsTabPage);
                break;

            case DocumentFormat.Doc:
                _optionsTabControl.TabPages.Add(_docOptionsTabPage);
                break;

            case DocumentFormat.Docx:
                _optionsTabControl.TabPages.Add(_docxOptionsTabPage);
                break;

            case DocumentFormat.Rtf:
                _optionsTabControl.TabPages.Add(_rtfOptionsTabPage);
                break;

            case DocumentFormat.Html:
                _optionsTabControl.TabPages.Add(_htmlOptionsTabPage);
                break;

            case DocumentFormat.Text:
                _optionsTabControl.TabPages.Add(_textOptionsTabPage);
                break;

            case DocumentFormat.Xps:
                _optionsTabControl.TabPages.Add(_xpsOptionsTabPage);
                break;

            case DocumentFormat.Xls:
                _optionsTabControl.TabPages.Add(_xlsOptionsTabPage);
                break;

            case DocumentFormat.Pub:
                _optionsTabControl.TabPages.Add(_ePubOptionsTabPage);
                break;

            case DocumentFormat.Mob:
                _optionsTabControl.TabPages.Add(_mobOptionsTabPage);
                break;

            case DocumentFormat.Svg:
                _optionsTabControl.TabPages.Add(_svgOptionsTabPage);
                break;

            case DocumentFormat.AltoXml:
                _optionsTabControl.TabPages.Add(_altoXmlOptionsTabPage);
                break;
            }

            _optionsTabControl.Visible = _optionsTabControl.TabPages.Count > 0;

            UpdateUIState();
        }
        public void SetDocumentWriter(DocumentWriter docWriter)
        {
            // Get the last format, options and document file name selected by the user
            _docWriter = docWriter;

            Properties.Settings settings      = new Properties.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))
                        _docWriter.LoadOptions(ms);
                }
                catch { }
            }

            // Get the formats
            // This is the order of importance, show these first then the rest as they come along
            DocumentFormat[] importantFormats =
            {
                DocumentFormat.Pdf,
                DocumentFormat.Docx,
                DocumentFormat.Rtf,
                DocumentFormat.Text,
                DocumentFormat.Doc,
                DocumentFormat.Xls,
                DocumentFormat.Html
            };

            List <DocumentFormat> formatsToAdd = new List <DocumentFormat>();

            Array temp = Enum.GetValues(typeof(DocumentFormat));
            List <DocumentFormat> allFormats = new List <DocumentFormat>();

            foreach (DocumentFormat format in temp)
            {
                allFormats.Add(format);
            }

            // Add important once first:
            foreach (DocumentFormat format in importantFormats)
            {
                formatsToAdd.Add(format);
                allFormats.Remove(format);
            }

            // Add rest
            formatsToAdd.AddRange(allFormats);

            MyFormat pdfFormat = null;

            foreach (DocumentFormat format in formatsToAdd)
            {
                if (format != DocumentFormat.User)
                {
                    string friendlyName = DocumentWriter.GetFormatFriendlyName(format);
                    string extension    = DocumentWriter.GetFormatFileExtension(format).ToUpper();

                    MyFormat mf = new MyFormat(format, friendlyName, extension);

                    _formatComboBox.Items.Add(mf);

                    if (mf.Format == initialFormat)
                    {
                        _formatComboBox.SelectedItem = mf;
                    }
                    else if (mf.Format == DocumentFormat.Pdf)
                    {
                        pdfFormat = mf;
                    }

                    switch (format)
                    {
                    case DocumentFormat.Pdf:
                        // Update the PDF options page
                    {
                        PdfDocumentOptions pdfOptions = _docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

                        // Clone it in case we change it in the Advance PDF options dialog
                        _pdfOptions = pdfOptions.Clone() as PdfDocumentOptions;

                        Array a = Enum.GetValues(typeof(PdfDocumentType));
                        foreach (PdfDocumentType i in a)
                        {
                            _pdfDocumentTypeComboBox.Items.Add(i);
                        }
                        _pdfDocumentTypeComboBox.SelectedItem = _pdfOptions.DocumentType;

                        _pdfImageOverTextCheckBox.Checked = _pdfOptions.ImageOverText;
                        _pdfLinearizedCheckBox.Checked    = _pdfOptions.Linearized;

                        if (string.IsNullOrEmpty(_pdfOptions.Creator))
                        {
                            _pdfOptions.Creator = "LEADTOOLS PDFWriter";
                        }
                        if (string.IsNullOrEmpty(_pdfOptions.Producer))
                        {
                            _pdfOptions.Producer = "LEAD Technologies, Inc.";
                        }
                    }
                    break;

                    case DocumentFormat.Doc:
                        // Update the DOC options page
                    {
                        DocDocumentOptions docOptions = _docWriter.GetOptions(DocumentFormat.Doc) as DocDocumentOptions;
                        _cbFramedDoc.Checked = (docOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Docx:
                        // Update the DOCX options page
                    {
                        DocxDocumentOptions docxOptions = _docWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;
                        _cbFramedDocX.Checked = (docxOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Rtf:
                        // Update the RTF options page
                    {
                        RtfDocumentOptions rtfOptions = _docWriter.GetOptions(DocumentFormat.Rtf) as RtfDocumentOptions;
                        _cbFramedRtf.Checked = (rtfOptions.TextMode == DocumentTextMode.Framed) ? true : false;
                    }
                    break;

                    case DocumentFormat.Html:
                        // Update the HTML options page
                    {
                        HtmlDocumentOptions htmlOptions = _docWriter.GetOptions(DocumentFormat.Html) as HtmlDocumentOptions;

                        Array a = Enum.GetValues(typeof(DocumentFontEmbedMode));
                        foreach (DocumentFontEmbedMode i in a)
                        {
                            _htmlEmbedFontModeComboBox.Items.Add(i);
                        }
                        _htmlEmbedFontModeComboBox.SelectedItem = htmlOptions.FontEmbedMode;

                        _htmlUseBackgroundColorCheckBox.Checked = htmlOptions.UseBackgroundColor;

                        _htmlBackgroundColorValueLabel.BackColor = ConvertColor(htmlOptions.BackgroundColor);

                        _htmlBackgroundColorLabel.Enabled      = _htmlUseBackgroundColorCheckBox.Checked;
                        _htmlBackgroundColorValueLabel.Enabled = _htmlUseBackgroundColorCheckBox.Checked;
                        _htmlBackgroundColorButton.Enabled     = _htmlUseBackgroundColorCheckBox.Checked;
                    }
                    break;

                    case DocumentFormat.Text:
                        // Update the TEXT options page
                    {
                        TextDocumentOptions textOptions = _docWriter.GetOptions(DocumentFormat.Text) as TextDocumentOptions;

                        Array a = Enum.GetValues(typeof(TextDocumentType));
                        foreach (TextDocumentType i in a)
                        {
                            _textDocumentTypeComboBox.Items.Add(i);
                        }
                        _textDocumentTypeComboBox.SelectedItem = textOptions.DocumentType;

                        _textAddPageNumberCheckBox.Checked = textOptions.AddPageNumber;
                        _textAddPageBreakCheckBox.Checked  = textOptions.AddPageBreak;
                        _textFormattedCheckBox.Checked     = textOptions.Formatted;
                    }
                    break;

                    case DocumentFormat.AltoXml:
                        // Update the ALTOXML options page
                    {
                        AltoXmlDocumentOptions altoXmlOptions = _docWriter.GetOptions(DocumentFormat.AltoXml) as AltoXmlDocumentOptions;
                        _altoXmlFileNameTextBox.Text               = altoXmlOptions.FileName;
                        _altoXmlSoftwareCreatorTextBox.Text        = altoXmlOptions.SoftwareCreator;
                        _altoXmlSoftwareNameTextBox.Text           = altoXmlOptions.SoftwareName;
                        _altoXmlApplicationDescriptionTextBox.Text = altoXmlOptions.ApplicationDescription;
                        _altoXmlFormattedCheckBox.Checked          = altoXmlOptions.Formatted;
                        _altoXmlIndentationTextBox.Text            = altoXmlOptions.Indentation;
                        _altoXmlSort.Checked              = altoXmlOptions.Sort;
                        _altoXmlPlainText.Checked         = altoXmlOptions.PlainText;
                        _altoXmlShowGlyphInfo.Checked     = altoXmlOptions.ShowGlyphInfo;
                        _altoXmlShowGlyphVariants.Checked = altoXmlOptions.ShowGlyphVariants;

                        Array a = Enum.GetValues(typeof(AltoXmlMeasurementUnit));
                        foreach (AltoXmlMeasurementUnit i in a)
                        {
                            _altoXmlMeasurementUnit.Items.Add(i);
                        }
                        _altoXmlMeasurementUnit.SelectedItem = altoXmlOptions.MeasurementUnit;
                    }
                    break;

                    case DocumentFormat.Emf:
                    case DocumentFormat.Xls:
                    case DocumentFormat.Pub:
                    case DocumentFormat.Mob:
                    case DocumentFormat.Svg:
                    default:
                        // These formats have no options
                        break;
                    }
                }
            }

            // Remove all the tab pages
            _optionsTabControl.TabPages.Clear();

            // If no format is selected, default to PDF
            if (_formatComboBox.SelectedIndex == -1)
            {
                if (pdfFormat != null)
                {
                    _formatComboBox.SelectedItem = pdfFormat;
                }
                else
                {
                    _formatComboBox.SelectedIndex = -1;
                }
            }

            _formatComboBox_SelectedIndexChanged(this, EventArgs.Empty);

            UpdateUIState();
        }