Beispiel #1
0
        public void UpdateInitialViewOptions(PDFInitialViewOptions initialViewOptions)
        {
            initialViewOptions.PageModeType   = (PDFPageModeType)_pageModeComboBox.SelectedItem;
            initialViewOptions.PageLayoutType = (PDFPageLayoutType)_pageLayoutComboBox.SelectedItem;
            if (_pageFitTypeComboBox.SelectedIndex >= 0 && _pageFitTypeComboBox.SelectedIndex < Enum.GetValues(typeof(PDFPageFitType)).Length)
            {
                // Selected item is one of the original enum members, so just use it
                initialViewOptions.PageFitType = (PDFPageFitType)_pageFitTypeComboBox.SelectedItem;
                initialViewOptions.ZoomPercent = 0;
            }
            else
            {
                string pageFitType = _pageFitTypeComboBox.Text;
                double value;
                if (double.TryParse(new string(pageFitType.Trim().TakeWhile(c => char.IsDigit(c) || c == '.').ToArray()), out value))
                {
                    initialViewOptions.ZoomPercent = value;
                }
            }

            int val;

            if (int.TryParse(_initialPageNumberEditBox.Text, out val))
            {
                initialViewOptions.PageNumber = val;
            }
            else
            {
                initialViewOptions.PageNumber = 1;
            }

            initialViewOptions.FitWindow       = _resizeWindowCheckBox.Checked;
            initialViewOptions.CenterWindow    = _centerWindowCheckBox.Checked;
            initialViewOptions.DisplayDocTitle = (_showDocumentTitleComboBox.SelectedIndex == 1) ? true : false;
            initialViewOptions.HideMenubar     = _hideMenuBarCheckBox.Checked;
            initialViewOptions.HideToolbar     = _hideToolBarCheckBox.Checked;
            initialViewOptions.HideWindowUI    = _hideWindowControlsCheckBox.Checked;
        }
Beispiel #2
0
        public void SetInitialViewOptions(PDFInitialViewOptions initialViewOptions, int totalPages)
        {
            // Initial View Options
            _pageModeComboBox.Items.Clear();
            Array a = Enum.GetValues(typeof(PDFPageModeType));

            foreach (PDFPageModeType i in a)
            {
                _pageModeComboBox.Items.Add(i);
            }
            _pageModeComboBox.SelectedItem = initialViewOptions.PageModeType;

            _pageLayoutComboBox.Items.Clear();
            a = Enum.GetValues(typeof(PDFPageLayoutType));
            foreach (PDFPageLayoutType i in a)
            {
                _pageLayoutComboBox.Items.Add(i);
            }
            _pageLayoutComboBox.SelectedItem = initialViewOptions.PageLayoutType;

            _pageFitTypeComboBox.Items.Clear();
            a = Enum.GetValues(typeof(PDFPageFitType));
            foreach (PDFPageFitType i in a)
            {
                _pageFitTypeComboBox.Items.Add(i);
            }

            int[] predefinedZoomValues = { 25, 50, 75, 100, 125, 150, 200, 400, 800, 1600, 2400, 3200, 6400 };
            foreach (int i in predefinedZoomValues)
            {
                _pageFitTypeComboBox.Items.Add(string.Format("{0}%", i));
            }
            if (initialViewOptions.ZoomPercent == 0)
            {
                _pageFitTypeComboBox.SelectedItem = initialViewOptions.PageFitType;
            }
            else
            {
                for (int i = Enum.GetValues(typeof(PDFPageFitType)).Length; i < _pageFitTypeComboBox.Items.Count; i++)
                {
                    string pageFitType = _pageFitTypeComboBox.Items[i] as string;
                    if (!string.IsNullOrEmpty(pageFitType))
                    {
                        double value;
                        if (double.TryParse(new string(pageFitType.Trim().TakeWhile(c => char.IsDigit(c) || c == '.').ToArray()), out value))
                        {
                            if (value == initialViewOptions.ZoomPercent)
                            {
                                _pageFitTypeComboBox.SelectedIndex = i;
                                break;
                            }
                        }
                    }
                }
            }

            if (_pageFitTypeComboBox.SelectedItem == null)
            {
                if (initialViewOptions.ZoomPercent == 0)
                {
                    _pageFitTypeComboBox.SelectedIndex = 0;
                }
                else
                {
                    _pageFitTypeComboBox.Text = string.Format("{0}%", initialViewOptions.ZoomPercent);
                }
            }

            _initialPageNumberEditBox.Text = initialViewOptions.PageNumber.ToString();
            _numberOfPagesLabel.Text       = string.Format("of {0}", totalPages);
            _resizeWindowCheckBox.Checked  = initialViewOptions.FitWindow;
            _centerWindowCheckBox.Checked  = initialViewOptions.CenterWindow;

            _showDocumentTitleComboBox.Items.Clear();
            _showDocumentTitleComboBox.Items.Add("File Name");
            _showDocumentTitleComboBox.Items.Add("Document Title");
            _showDocumentTitleComboBox.SelectedIndex = (initialViewOptions.DisplayDocTitle) ? 1 : 0;
            _hideMenuBarCheckBox.Checked             = initialViewOptions.HideMenubar;
            _hideToolBarCheckBox.Checked             = initialViewOptions.HideToolbar;
            _hideWindowControlsCheckBox.Checked      = initialViewOptions.HideWindowUI;
        }
        public void SetDocument(PDFFile document, bool showCompatibilityLevel, bool showSecurityOptions, bool showOptimizationOptions, bool showInitialViewOptions, int firstPageNumber, int lastPageNumber)
        {
            _showSecurityOptions     = showSecurityOptions;
            _showOptimizationOptions = showOptimizationOptions;
            _showInitialViewOptions  = showInitialViewOptions;

            _compatibilityLevelComboBox.Visible      = showCompatibilityLevel;
            _compatibilityLevelLabel.Visible         = showCompatibilityLevel;
            _compatibilityLevelComboBox.SelectedItem = document.CompatibilityLevel;

            if (document.DocumentProperties != null)
            {
                _documentPropertiesControl.SetDocumentProperties(document.DocumentProperties, false);
            }
            else
            {
                PDFDocumentProperties documentProps = new PDFDocumentProperties();
                documentProps.Created  = DateTime.Now;
                documentProps.Modified = DateTime.Now;

                _documentPropertiesControl.SetDocumentProperties(documentProps, false);
            }

            if (showSecurityOptions)
            {
                _updateSecurityOptionsCheckBox.Checked = document.SecurityOptions != null;

                if (document.SecurityOptions != null)
                {
                    _securityOptionsControl.SetSecurityOptions(document.SecurityOptions);
                }
                else
                {
                    PDFSecurityOptions securityOptions = new PDFSecurityOptions();
                    securityOptions.PrintEnabled            = true;
                    securityOptions.HighQualityPrintEnabled = true;
                    securityOptions.CopyEnabled             = true;
                    securityOptions.EditEnabled             = true;
                    securityOptions.AnnotationsEnabled      = true;
                    securityOptions.AssemblyEnabled         = true;
                    securityOptions.EncryptionMode          = PDFEncryptionMode.RC40Bit;
                    _securityOptionsControl.SetSecurityOptions(securityOptions);
                }
                _securityOptionsControl.SetCompatibilityLevel(document.CompatibilityLevel);
            }

#if LEADTOOLS_V19_OR_LATER
            if (showOptimizationOptions)
            {
                _updateOptimizationOptionsCheckBox.Checked = document.OptimizerOptions != null;

                if (document.OptimizerOptions != null)
                {
                    _optimizerOptionsControl.SetOptimizerOptions(document.OptimizerOptions);
                }
                else
                {
                    PDFOptimizerOptions optimizerOptions = new PDFOptimizerOptions();
                    optimizerOptions.AutoOptimizerMode          = PDFAutoOptimizerMode.Customized;
                    optimizerOptions.ColorImageDownsamplingMode = PDFDownsamplingMode.Average;
                    optimizerOptions.ColorImageDownsampleFactor = 1.5;
                    optimizerOptions.ColorImageDPI         = 150;
                    optimizerOptions.ColorImageCompression = RasterImageFormat.Jpeg;

                    optimizerOptions.GrayImageDownsamplingMode = PDFDownsamplingMode.Average;
                    optimizerOptions.GrayImageDownsampleFactor = 1.5;
                    optimizerOptions.GrayImageDPI         = 150;
                    optimizerOptions.GrayImageCompression = RasterImageFormat.RawFlate;

                    optimizerOptions.MonoImageDownsamplingMode = PDFDownsamplingMode.Average;
                    optimizerOptions.MonoImageDownsampleFactor = 1.5;
                    optimizerOptions.MonoImageDPI         = 150;
                    optimizerOptions.MonoImageCompression = RasterImageFormat.FaxG4;

                    _optimizerOptionsControl.SetOptimizerOptions(optimizerOptions);
                }
            }

            if (showInitialViewOptions)
            {
                _updateInitialViewOptionsCheckBox.Checked = document.InitialViewOptions != null;

                int totalPages = (lastPageNumber == -1) ? document.Pages.Count - firstPageNumber + 1 : lastPageNumber - firstPageNumber + 1;
                if (document.InitialViewOptions != null)
                {
                    _initialViewOptionsControl.SetInitialViewOptions(document.InitialViewOptions, totalPages);
                }
                else
                {
                    PDFInitialViewOptions initialViewOptions = new PDFInitialViewOptions();
                    initialViewOptions.AutoPrint       = false;
                    initialViewOptions.CenterWindow    = false;
                    initialViewOptions.DisplayDocTitle = false;
                    initialViewOptions.FitWindow       = false;
                    initialViewOptions.HideMenubar     = false;
                    initialViewOptions.HideToolbar     = false;
                    initialViewOptions.HideWindowUI    = false;
                    initialViewOptions.PageFitType     = PDFPageFitType.Default;
                    initialViewOptions.PageLayoutType  = PDFPageLayoutType.OneColumnDisplay;
                    initialViewOptions.PageModeType    = PDFPageModeType.PageOnly;
                    initialViewOptions.PageNumber      = 1;
                    initialViewOptions.Position        = new PDFPoint(0, 0);
                    initialViewOptions.ZoomPercent     = 0;

                    _initialViewOptionsControl.SetInitialViewOptions(initialViewOptions, totalPages);
                }
            }
#endif // #if LEADTOOLS_V19_OR_LATER

            UpdateUIState(showSecurityOptions, showOptimizationOptions, showInitialViewOptions);
        }