Esempio n. 1
0
        private void Startup()
        {
            Properties.Settings settings = new Properties.Settings();

            _docWriter = new DocumentWriter();

            DocDocumentOptions docOptions = _docWriter.GetOptions(DocumentFormat.Doc) as DocDocumentOptions;

            docOptions.TextMode = DocumentTextMode.Framed;

            DocxDocumentOptions docxOptions = _docWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;

            docxOptions.TextMode = DocumentTextMode.Framed;

            RtfDocumentOptions rtfOptions = _docWriter.GetOptions(DocumentFormat.Rtf) as RtfDocumentOptions;

            rtfOptions.TextMode = DocumentTextMode.Framed;

            AltoXmlDocumentOptions altoXmlOptions = _docWriter.GetOptions(DocumentFormat.AltoXml) as AltoXmlDocumentOptions;

            altoXmlOptions.Formatted = true;

            _documentFormatOptionsControl.SelectedFormatChanged += new EventHandler <EventArgs>(_documentFormatOptionsControl_SelectedFormatChanged);

            _documentFormatOptionsControl.SetDocumentWriter(_docWriter);

            _docWriter.Progress += new EventHandler <DocumentProgressEventArgs>(DocumentWriterInstance_Progress);

            _viewDocumentCheckBox.Checked          = settings.ViewFinalDocument;
            _outputFileNameTextBox.Text            = settings.OutputFileName;
            _ltdDocumentTypeComboBox.SelectedIndex = settings.LTDDocumentTypeIndex;

            UpdateUIState(false);
        }
Esempio n. 2
0
        private static void SetDocumentWriterOptions(DocumentWriter docWriter, DocumentFormat format)
        {
            switch (format)
            {
#if LEADTOOLS_V19_OR_LATER
            case DocumentFormat.Ltd:
#else
            case DocumentFormat.Ltd:
#endif // #if LEADTOOLS_V19_OR_LATER
            case DocumentFormat.Pdf:
            case DocumentFormat.Html:
            case DocumentFormat.Text:
            case DocumentFormat.Emf:
            case DocumentFormat.Xps:
            case DocumentFormat.Xls:
                break;

            case DocumentFormat.Doc:
            {
                DocDocumentOptions docOptions = docWriter.GetOptions(format) as DocDocumentOptions;

                docOptions.TextMode = DocumentTextMode.Framed;

                docWriter.SetOptions(format, docOptions);
            }
            break;

            case DocumentFormat.Rtf:
            {
                RtfDocumentOptions rtfOptions = docWriter.GetOptions(format) as RtfDocumentOptions;

                rtfOptions.TextMode = DocumentTextMode.Framed;

                docWriter.SetOptions(format, rtfOptions);
            }
            break;

            case DocumentFormat.Docx:
            {
                DocxDocumentOptions docxOptions = docWriter.GetOptions(format) as DocxDocumentOptions;

                docxOptions.TextMode = DocumentTextMode.Framed;

                docWriter.SetOptions(format, docxOptions);
            }
            break;

            default:
                throw new ArgumentException("Invalid format");
            }
        }
Esempio n. 3
0
        public static void ExportPdfViaSvg(string filename)
        {
            var outputFile = Path.Combine(Leadtools.Demo.Support.Path.GetOutputPath(), Path.GetFileNameWithoutExtension(filename) + "_Svg.pdf");

            // Setup a new RasterCodecs object
            using (var codecs = new RasterCodecs())
            {
                // Check to see if we can use this method
                // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~canloadsvg(string).html
                if (!codecs.CanLoadSvg(filename))
                {
                    Console.WriteLine("\nCannot load this file as SVG for conversion to PDF.\nSee: https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~canloadsvg(string).html#remarksSectionHeading");
                    return;
                }

                codecs.Options.RasterizeDocument.Load.Resolution = 300;

                // Get the number of pages in the input document
                var pageCount = codecs.GetTotalPages(filename);

                // Create a new instance of the LEADTOOLS Document Writer
                var docWriter = new DocumentWriter();

                // Set the PDF options
                // https://www.leadtools.com/help/leadtools/v19/dh/ft/leadtools.forms.documentwriters~leadtools.forms.documentwriters.pdfdocumentoptions.html
                var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
                if (pdfOptions != null)
                {
                    pdfOptions.DocumentType = PdfDocumentType.Pdf;
                    docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions);
                }

                // Create a new PDF document
                docWriter.BeginDocument(outputFile, DocumentFormat.Pdf);

                var message = "";
                // Loop through all the pages
                for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++)
                {
                    // Get the page as SVG
                    // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~loadsvg.html
                    var page           = new DocumentSvgPage();
                    var lastMessageLen = message.Length;

                    message = string.Format("\rConverting page {0} of {1}", pageNumber, pageCount);
                    var diff = lastMessageLen - message.Length;
                    Console.Write("{0}{1}", message, (diff > 0 ? new string( ' ', diff ) : ""));
                    using (page.SvgDocument = codecs.LoadSvg(filename, pageNumber, null))
                    {
                        // Add the page
                        docWriter.AddPage(page);
                    }
                }
                Console.Write("\r{0}\r", new String(' ', message.Length));
                // Finally, finish writing the PDF file on disk
                docWriter.EndDocument();
            }
        }
        private void SetDocumentWriterOptions(DocumentWriter docWriter)
        {
            DocDocumentOptions docOptions = docWriter.GetOptions(DocumentFormat.Doc) as DocDocumentOptions;

            docOptions.TextMode = DocumentTextMode.Framed;

            DocxDocumentOptions docxOptions = docWriter.GetOptions(DocumentFormat.Docx) as DocxDocumentOptions;

            docxOptions.TextMode = DocumentTextMode.Framed;

            RtfDocumentOptions rtfOptions = docWriter.GetOptions(DocumentFormat.Rtf) as RtfDocumentOptions;

            rtfOptions.TextMode = DocumentTextMode.Framed;

            AltoXmlDocumentOptions altoXmlOptions = docWriter.GetOptions(DocumentFormat.AltoXml) as AltoXmlDocumentOptions;

            altoXmlOptions.Formatted = true;
        }
Esempio n. 5
0
        private DocumentWriter OpenDocumentWriterInstance(double pageWidth, double pageHeight, int resolution)
        {
            DocumentWriter documentWriterInstance = null;

            try
            {
                documentWriterInstance = new DocumentWriter();
                {
                    PdfDocumentOptions pdfOptions = documentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;

                    int emptyPageResolution = resolution;
                    if ((int)pageWidth == 0)
                    {
                        pageWidth = 11;
                    }
                    if ((int)pageHeight == 0)
                    {
                        pageHeight = 8.5;
                    }
                    pdfOptions.EmptyPageResolution = emptyPageResolution;
                    pdfOptions.DocumentResolution  = emptyPageResolution;
                    pdfOptions.EmptyPageWidth      = pageWidth;
                    pdfOptions.EmptyPageHeight     = pageHeight;
                    pdfOptions.PageRestriction     = DocumentPageRestriction.Relaxed;
                    pdfOptions.PrintEnabled        = true;
                    pdfOptions.ImageOverText       = true;

                    documentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions);
                }

                return(documentWriterInstance);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 6
0
        public SaveDocumentDialog(IOcrDocument ocrDocument, DocumentFormat initialFormat, string initialFileName, bool isCustomFileName, string outputDir, bool viewDocument)
        {
            InitializeComponent();

            _ocrDocument = ocrDocument;
            _outputDir   = outputDir;


            // Get the formats
            // This is the order of importance, show these first then the rest as they come along
            DocumentFormat[] importantFormats =
            {
                DocumentFormat.Ltd,
                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;

            DocumentWriter      docWriter          = _ocrDocument.Engine.DocumentWriterInstance;
            IOcrDocumentManager ocrDocumentManager = _ocrDocument.Engine.DocumentManager;

            string[] engineSupportedFormatNames = ocrDocumentManager.GetSupportedEngineFormats();

            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 && engineSupportedFormatNames.Length == 0)
                {
                    addFormat = false;
                }

                if (addFormat)
                {
                    string friendlyName;
                    if (format == DocumentFormat.User)
                    {
                        friendlyName = "Engine native";
                    }
                    else
                    {
                        friendlyName = DocumentWriter.GetFormatFriendlyName(format);
                    }

                    MyFormat mf = new MyFormat(format, friendlyName);

                    _formatComboBox.Items.Add(mf);

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

                switch (format)
                {
                case DocumentFormat.User:
                    // Update the User (Engine) options page
                {
                    foreach (string engineFormatName in engineSupportedFormatNames)
                    {
                        MyEngineFormat mef = new MyEngineFormat(
                            engineFormatName,
                            ocrDocumentManager.GetEngineFormatFriendlyName(engineFormatName));
                        _userFormatNameComboBox.Items.Add(mef);

                        if (mef.Format == ocrDocumentManager.EngineFormat)
                        {
                            _userFormatNameComboBox.SelectedItem = mef;
                        }
                    }

                    if (_userFormatNameComboBox.SelectedItem == null && _userFormatNameComboBox.Items.Count > 0)
                    {
                        _userFormatNameComboBox.SelectedIndex = 0;
                    }
                }
                break;

                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)
                    {
                        // PDFA does NOT support Arabic characters so we are not adding it in case of Arabic OCR engine.
                        if (i == PdfDocumentType.PdfA && _ocrDocument.Engine.EngineType == OcrEngineType.OmniPageArabic)
                        {
                            continue;
                        }

                        _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)
                    {
                        if (i == TextDocumentType.Ansi)
                        {
                            if (textOptions.DocumentType == TextDocumentType.Ansi)
                            {
                                textOptions.DocumentType = TextDocumentType.Unicode;
                            }
                            if (_ocrDocument.Engine.EngineType == 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
                {
                    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.Ltd:
                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;
            _initialFileName  = initialFileName;
            _isCustomFileName = isCustomFileName;

            if (!string.IsNullOrEmpty(_outputDir))
            {
                MyFormat mf = _formatComboBox.SelectedItem as MyFormat;

                char[] trimChars = { '\\' };
                _fileNameTextBox.Text = _outputDir.TrimEnd(trimChars) + "\\" + Path.GetFileName(initialFileName);
                if (!_isCustomFileName)
                {
                    _fileNameTextBox.Text += "." + GetFileExtension(mf.Format);
                }
            }
            else
            {
                _fileNameTextBox.Text = initialFileName;
            }

            _formatComboBox_SelectedIndexChanged(this, EventArgs.Empty);
            UpdateUIState();
        }
Esempio n. 7
0
        private void _okButton_Click(object sender, EventArgs e)
        {
            DocumentWriter      docWriter          = _ocrDocument.Engine.DocumentWriterInstance;
            IOcrDocumentManager ocrDocumentManager = _ocrDocument.Engine.DocumentManager;

            // Save the options
            MyFormat mf = _formatComboBox.SelectedItem as MyFormat;

            DocumentOptions documentOptions;

            if (mf.Format != DocumentFormat.User)
            {
                documentOptions = docWriter.GetOptions(mf.Format);
            }
            else
            {
                documentOptions = null;
            }

            switch (mf.Format)
            {
            case DocumentFormat.User:
                // Update the User (Engine) options
            {
                MyEngineFormat mef = _userFormatNameComboBox.SelectedItem as MyEngineFormat;
                ocrDocumentManager.EngineFormat = mef.Format;
            }
            break;

            case DocumentFormat.Pdf:
                // Update the PDF options
            {
                PdfDocumentOptions pdfOptions = documentOptions as PdfDocumentOptions;

                pdfOptions.DocumentType    = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem;
                pdfOptions.ImageOverText   = _pdfImageOverTextCheckBox.Checked;
                pdfOptions.Linearized      = _pdfLinearizedCheckBox.Checked;
                pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed;

                // Description options
                pdfOptions.Title    = _pdfOptions.Title;
                pdfOptions.Subject  = _pdfOptions.Subject;
                pdfOptions.Keywords = _pdfOptions.Keywords;
                pdfOptions.Author   = _pdfOptions.Author;
                pdfOptions.Creator  = _pdfOptions.Creator;
                pdfOptions.Producer = _pdfOptions.Producer;

                // Fonts options
                pdfOptions.FontEmbedMode = _pdfOptions.FontEmbedMode;

                // Security options
                pdfOptions.Protected = _pdfOptions.Protected;
                if (pdfOptions.Protected)
                {
                    pdfOptions.UserPassword            = _pdfOptions.UserPassword;
                    pdfOptions.OwnerPassword           = _pdfOptions.OwnerPassword;
                    pdfOptions.EncryptionMode          = _pdfOptions.EncryptionMode;
                    pdfOptions.PrintEnabled            = _pdfOptions.PrintEnabled;
                    pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled;
                    pdfOptions.CopyEnabled             = _pdfOptions.CopyEnabled;
                    pdfOptions.EditEnabled             = _pdfOptions.EditEnabled;
                    pdfOptions.AnnotationsEnabled      = _pdfOptions.AnnotationsEnabled;
                    pdfOptions.AssemblyEnabled         = _pdfOptions.AssemblyEnabled;
                }

                // Compression options
                pdfOptions.OneBitImageCompression  = _pdfOptions.OneBitImageCompression;
                pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression;
                pdfOptions.QualityFactor           = _pdfOptions.QualityFactor;
                pdfOptions.ImageOverTextSize       = _pdfOptions.ImageOverTextSize;
                pdfOptions.ImageOverTextMode       = _pdfOptions.ImageOverTextMode;

                // Initial View Options
                pdfOptions.PageModeType      = _pdfOptions.PageModeType;
                pdfOptions.PageLayoutType    = _pdfOptions.PageLayoutType;
                pdfOptions.PageFitType       = _pdfOptions.PageFitType;
                pdfOptions.ZoomPercent       = _pdfOptions.ZoomPercent;
                pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber;
                pdfOptions.FitWindow         = _pdfOptions.FitWindow;
                pdfOptions.CenterWindow      = _pdfOptions.CenterWindow;
                pdfOptions.DisplayDocTitle   = _pdfOptions.DisplayDocTitle;
                pdfOptions.HideMenubar       = _pdfOptions.HideMenubar;
                pdfOptions.HideToolbar       = _pdfOptions.HideToolbar;
                pdfOptions.HideWindowUI      = _pdfOptions.HideWindowUI;
            }
            break;

            case DocumentFormat.Doc:
                // Update the DOC options
            {
                DocDocumentOptions docOptions = documentOptions as DocDocumentOptions;
                docOptions.TextMode = (_cbFramedDoc.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Docx:
                // Update the DOC options
            {
                DocxDocumentOptions docxOptions = documentOptions as DocxDocumentOptions;
                docxOptions.TextMode = (_cbFramedDocX.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Rtf:
                // Update the RTF options
            {
                RtfDocumentOptions rtfOptions = documentOptions as RtfDocumentOptions;
                rtfOptions.TextMode = (_cbFramedRtf.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Html:
                // Update the HTML options
            {
                HtmlDocumentOptions htmlOptions = documentOptions as HtmlDocumentOptions;
                htmlOptions.FontEmbedMode      = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem;
                htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked;
                htmlOptions.BackgroundColor    = MainForm.ConvertColor(_htmlBackgroundColorValueLabel.BackColor);
            }
            break;

            case DocumentFormat.Text:
                // Update the TEXT options
            {
                TextDocumentOptions textOptions = documentOptions as TextDocumentOptions;
                textOptions.DocumentType  = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem;
                textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked;
                textOptions.AddPageBreak  = _textAddPageBreakCheckBox.Checked;
                textOptions.Formatted     = _textFormattedCheckBox.Checked;
            }
            break;

            case DocumentFormat.AltoXml:
                // Update the ALTOXML options
            {
                AltoXmlDocumentOptions altoXmlOptions = documentOptions as AltoXmlDocumentOptions;
                altoXmlOptions.FileName               = _altoXmlFileNameTextBox.Text;
                altoXmlOptions.SoftwareCreator        = _altoXmlSoftwareCreatorTextBox.Text;
                altoXmlOptions.SoftwareName           = _altoXmlSoftwareNameTextBox.Text;
                altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text;
                altoXmlOptions.Formatted              = _altoXmlFormattedCheckBox.Checked;
                altoXmlOptions.Indentation            = (altoXmlOptions.Formatted) ? _altoXmlIndentationTextBox.Text : "";
                altoXmlOptions.Sort              = _altoXmlSort.Checked;
                altoXmlOptions.PlainText         = _altoXmlPlainText.Checked;
                altoXmlOptions.ShowGlyphInfo     = _altoXmlShowGlyphInfo.Checked;
                altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariants.Checked;
                altoXmlOptions.MeasurementUnit   = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnit.SelectedItem;
            }
            break;

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

            if (documentOptions != null)
            {
                docWriter.SetOptions(mf.Format, documentOptions);
            }

            // Get the save paramters
            _selectedFileName     = _fileNameTextBox.Text;
            _selectedFormat       = mf.Format;
            _selectedViewDocument = _viewDocumentCheckBox.Checked;

            if (_isCustomFileName)
            {
                _outputDir = Path.GetDirectoryName(SelectedFileName);
            }
        }
Esempio n. 8
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);
        }
        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();
        }
        private void _okButton_Click(object sender, EventArgs e)
        {
            DocumentOptions options = _documentWriter.GetOptions(_format);

            switch (_format)
            {
            case DocumentFormat.Pdf:
                // Update the PDF options
            {
                PdfDocumentOptions pdfOptions = options as PdfDocumentOptions;
                pdfOptions.DocumentType    = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem;
                pdfOptions.ImageOverText   = _pdfImageOverTextCheckBox.Checked;
                pdfOptions.Linearized      = _pdfLinearizedCheckBox.Checked;
                pdfOptions.FontEmbedMode   = _pdfOptions.FontEmbedMode;
                pdfOptions.Linearized      = _pdfOptions.Linearized;
                pdfOptions.Title           = _pdfOptions.Title;
                pdfOptions.Subject         = _pdfOptions.Subject;
                pdfOptions.Keywords        = _pdfOptions.Keywords;
                pdfOptions.Author          = _pdfOptions.Author;
                pdfOptions.Creator         = _pdfOptions.Creator;
                pdfOptions.Producer        = _pdfOptions.Producer;
                pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed;

                pdfOptions.Protected = _pdfOptions.Protected;
                if (pdfOptions.Protected)
                {
                    pdfOptions.UserPassword            = _pdfOptions.UserPassword;
                    pdfOptions.OwnerPassword           = _pdfOptions.OwnerPassword;
                    pdfOptions.EncryptionMode          = _pdfOptions.EncryptionMode;
                    pdfOptions.PrintEnabled            = _pdfOptions.PrintEnabled;
                    pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled;
                    pdfOptions.CopyEnabled             = _pdfOptions.CopyEnabled;
                    pdfOptions.EditEnabled             = _pdfOptions.EditEnabled;
                    pdfOptions.AnnotationsEnabled      = _pdfOptions.AnnotationsEnabled;
                    pdfOptions.AssemblyEnabled         = _pdfOptions.AssemblyEnabled;
                }

                // Compression options
                pdfOptions.OneBitImageCompression  = _pdfOptions.OneBitImageCompression;
                pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression;
                pdfOptions.QualityFactor           = _pdfOptions.QualityFactor;
                pdfOptions.ImageOverTextSize       = _pdfOptions.ImageOverTextSize;
                pdfOptions.ImageOverTextMode       = _pdfOptions.ImageOverTextMode;

                // Linearized
                pdfOptions.Linearized = _pdfOptions.Linearized;

                // Initial View Options
                pdfOptions.PageModeType      = _pdfOptions.PageModeType;
                pdfOptions.PageLayoutType    = _pdfOptions.PageLayoutType;
                pdfOptions.PageFitType       = _pdfOptions.PageFitType;
                pdfOptions.ZoomPercent       = _pdfOptions.ZoomPercent;
                pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber;
                pdfOptions.FitWindow         = _pdfOptions.FitWindow;
                pdfOptions.CenterWindow      = _pdfOptions.CenterWindow;
                pdfOptions.DisplayDocTitle   = _pdfOptions.DisplayDocTitle;
                pdfOptions.HideMenubar       = _pdfOptions.HideMenubar;
                pdfOptions.HideToolbar       = _pdfOptions.HideToolbar;
                pdfOptions.HideWindowUI      = _pdfOptions.HideWindowUI;
            }
            break;

            case DocumentFormat.Doc:
                // Update the DOC options
            {
                DocDocumentOptions docOptions = options as DocDocumentOptions;
                docOptions.TextMode = (_docFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Docx:
                // Update the DOCX options
            {
                DocxDocumentOptions docxOptions = options as DocxDocumentOptions;
                docxOptions.TextMode = (_docxFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Rtf:
                // Update the RTF options
            {
                RtfDocumentOptions rtfOptions = options as RtfDocumentOptions;
                rtfOptions.TextMode = (_rtfFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Html:
                // Update the HTML options
            {
                HtmlDocumentOptions htmlOptions = options as HtmlDocumentOptions;
                htmlOptions.FontEmbedMode      = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem;
                htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked;
                htmlOptions.BackgroundColor    = Leadtools.Demos.Converters.FromGdiPlusColor(_htmlBackgroundColorValueLabel.BackColor);
            }
            break;

            case DocumentFormat.Text:
                // Update the TEXT options
            {
                TextDocumentOptions textOptions = options as TextDocumentOptions;
                textOptions.DocumentType  = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem;
                textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked;
                textOptions.AddPageBreak  = _textAddPageBreakCheckBox.Checked;
                textOptions.Formatted     = _textFormattedCheckBox.Checked;
            }
            break;

            case DocumentFormat.AltoXml:
                // Update the ALTOXML options
            {
                AltoXmlDocumentOptions altoXmlOptions = options as AltoXmlDocumentOptions;
                altoXmlOptions.MeasurementUnit        = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnitComboBox.SelectedItem;
                altoXmlOptions.FileName               = _altoXmlFileNameTextBox.Text;
                altoXmlOptions.SoftwareCreator        = _altoXmlSoftwareCreatorTextBox.Text;
                altoXmlOptions.SoftwareName           = _altoXmlSoftwareNameTextBox.Text;
                altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text;
                altoXmlOptions.Formatted              = _altoXmlFormattedCheckBox.Checked;
                altoXmlOptions.Indentation            = _altoXmlIndentationTextBox.Text;
                altoXmlOptions.Sort              = _altoXmlSortCheckBox.Checked;
                altoXmlOptions.PlainText         = _altoXmlPlainTextCheckBox.Checked;
                altoXmlOptions.ShowGlyphInfo     = _altoXmlShowGlyphInfoCheckBox.Checked;
                altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariantsCheckBox.Checked;
            }
            break;

            case DocumentFormat.Ltd:
            case DocumentFormat.Emf:
            default:
                // These formats have no options
                break;
            }

            if (options != null)
            {
                _documentWriter.SetOptions(_format, options);
            }
        }
Esempio n. 11
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();
        }
        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();
        }
        public void UpdateDocumentWriterOptions()
        {
            // Save the options
            DocumentFormat format = this.SelectedDocumentFormat;

            Properties.Settings settings = new Properties.Settings();
            settings.Format = format.ToString();

            // Update the options
            DocumentOptions documentOptions = _docWriter.GetOptions(format);

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

                pdfOptions.DocumentType    = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem;
                pdfOptions.ImageOverText   = _pdfImageOverTextCheckBox.Checked;
                pdfOptions.Linearized      = _pdfLinearizedCheckBox.Checked;
                pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed;

                // Description options
                pdfOptions.Title    = _pdfOptions.Title;
                pdfOptions.Subject  = _pdfOptions.Subject;
                pdfOptions.Keywords = _pdfOptions.Keywords;
                pdfOptions.Author   = _pdfOptions.Author;
                pdfOptions.Creator  = _pdfOptions.Creator;
                pdfOptions.Producer = _pdfOptions.Producer;

                // Fonts options
                pdfOptions.FontEmbedMode = _pdfOptions.FontEmbedMode;
                pdfOptions.Linearized    = _pdfOptions.Linearized;

                // Security options
                pdfOptions.Protected = _pdfOptions.Protected;
                if (pdfOptions.Protected)
                {
                    pdfOptions.UserPassword            = _pdfOptions.UserPassword;
                    pdfOptions.OwnerPassword           = _pdfOptions.OwnerPassword;
                    pdfOptions.EncryptionMode          = _pdfOptions.EncryptionMode;
                    pdfOptions.PrintEnabled            = _pdfOptions.PrintEnabled;
                    pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled;
                    pdfOptions.CopyEnabled             = _pdfOptions.CopyEnabled;
                    pdfOptions.EditEnabled             = _pdfOptions.EditEnabled;
                    pdfOptions.AnnotationsEnabled      = _pdfOptions.AnnotationsEnabled;
                    pdfOptions.AssemblyEnabled         = _pdfOptions.AssemblyEnabled;
                }

                // Compression options
                pdfOptions.OneBitImageCompression  = _pdfOptions.OneBitImageCompression;
                pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression;
                pdfOptions.QualityFactor           = _pdfOptions.QualityFactor;
                pdfOptions.ImageOverTextSize       = _pdfOptions.ImageOverTextSize;
                pdfOptions.ImageOverTextMode       = _pdfOptions.ImageOverTextMode;

                // Initial View Options
                pdfOptions.PageModeType      = _pdfOptions.PageModeType;
                pdfOptions.PageLayoutType    = _pdfOptions.PageLayoutType;
                pdfOptions.PageFitType       = _pdfOptions.PageFitType;
                pdfOptions.ZoomPercent       = _pdfOptions.ZoomPercent;
                pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber;
                pdfOptions.FitWindow         = _pdfOptions.FitWindow;
                pdfOptions.CenterWindow      = _pdfOptions.CenterWindow;
                pdfOptions.DisplayDocTitle   = _pdfOptions.DisplayDocTitle;
                pdfOptions.HideMenubar       = _pdfOptions.HideMenubar;
                pdfOptions.HideToolbar       = _pdfOptions.HideToolbar;
                pdfOptions.HideWindowUI      = _pdfOptions.HideWindowUI;
            }
            break;

            case DocumentFormat.Doc:
                // Update the DOC options
            {
                DocDocumentOptions docOptions = documentOptions as DocDocumentOptions;
                docOptions.TextMode = (_cbFramedDoc.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Docx:
                // Update the DOCX options
            {
                DocxDocumentOptions docxOptions = documentOptions as DocxDocumentOptions;
                docxOptions.TextMode = (_cbFramedDocX.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Rtf:
                // Update the RTF options
            {
                RtfDocumentOptions rtfOptions = documentOptions as RtfDocumentOptions;
                rtfOptions.TextMode = (_cbFramedRtf.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed;
            }
            break;

            case DocumentFormat.Html:
                // Update the HTML options
            {
                HtmlDocumentOptions htmlOptions = documentOptions as HtmlDocumentOptions;
                htmlOptions.FontEmbedMode      = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem;
                htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked;
                htmlOptions.BackgroundColor    = ConvertColor(_htmlBackgroundColorValueLabel.BackColor);
            }
            break;

            case DocumentFormat.Text:
                // Update the TEXT options
            {
                TextDocumentOptions textOptions = documentOptions as TextDocumentOptions;
                textOptions.DocumentType  = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem;
                textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked;
                textOptions.AddPageBreak  = _textAddPageBreakCheckBox.Checked;
                textOptions.Formatted     = _textFormattedCheckBox.Checked;
            }
            break;

            case DocumentFormat.AltoXml:
                // Update the DOCX options
            {
                AltoXmlDocumentOptions altoXmlOptions = documentOptions as AltoXmlDocumentOptions;
                altoXmlOptions.FileName               = _altoXmlFileNameTextBox.Text;
                altoXmlOptions.SoftwareCreator        = _altoXmlSoftwareCreatorTextBox.Text;
                altoXmlOptions.SoftwareName           = _altoXmlSoftwareNameTextBox.Text;
                altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text;
                altoXmlOptions.Formatted              = _altoXmlFormattedCheckBox.Checked;
                altoXmlOptions.Indentation            = _altoXmlIndentationTextBox.Text;
                altoXmlOptions.Sort              = _altoXmlSort.Checked;
                altoXmlOptions.PlainText         = _altoXmlPlainText.Checked;
                altoXmlOptions.ShowGlyphInfo     = _altoXmlShowGlyphInfo.Checked;
                altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariants.Checked;
                altoXmlOptions.MeasurementUnit   = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnit.SelectedItem;
            }
            break;

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

            if (documentOptions != null)
            {
                _docWriter.SetOptions(format, documentOptions);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                _docWriter.SaveOptions(ms);
                settings.FormatOptionsXml = Encoding.Unicode.GetString(ms.ToArray());
            }

            settings.Save();
        }