Exemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _viewerPanel = GetTemplateChild(ViewerPanel) as Grid;
            _thumbnailPanel = GetTemplateChild(ThumbnailPanel) as Grid;
            _bookmarkPanel = GetTemplateChild(BookmarkPanel) as Grid;

            var createOptions = new DocumentViewerCreateOptions
            {
                // The middle panel for the view 
                ViewContainer = _viewerPanel,
                // The left panel for the thumbnails 
                ThumbnailsContainer = _thumbnailPanel,
                // The right panel is for bookmarks 
                BookmarksContainer = _bookmarkPanel,
                // Not using annotations for now 
                UseAnnotations = false
            };

            _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
            // We prefer SVG viewing 
            _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;

            // Load a document 
            var fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Leadtools.pdf";
            var document = DocumentFactory.LoadFromFile(
               fileName,
               new LoadDocumentOptions { UseCache = DocumentFactory.Cache != null });

           
            // Set it in the viewer 
            _documentViewer.SetDocument(document);

        }
Exemplo n.º 2
0
        private void InitDocumentViewer()
        {
            // Create the document viewer using panels of a System.Windows.Forms.SplitterPanel
            var createOptions = new Leadtools.Documents.UI.DocumentViewerCreateOptions();

            createOptions.ViewContainer       = this.splitContainer1.Panel2;
            createOptions.ThumbnailsContainer = this.splitContainer1.Panel1;
            _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
            _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;
            _documentViewer.Commands.Run(DocumentViewerCommands.InteractivePanZoom);
            _documentViewer.Text.AutoGetText = true;
        }
Exemplo n.º 3
0
        // Create the document viewer
        private void InitDocumentViewer(string documentPath, DocumentScanType scanType)
        {
            var createOptions = new DocumentViewerCreateOptions();

            // Set the UI part where the main view is displayed
            createOptions.ViewContainer  = DocumentViewerContainer;
            createOptions.UseAnnotations = false;

            // Now create the viewer
            _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
            // Set the user name
            _documentViewer.UserName = Environment.UserName;
            // We prefer SVG viewing (if supported)
            _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;

            var imageViewer = _documentViewer.View.ImageViewer;

            if (scanType == DocumentScanType.Document)
            {
                imageViewer.ScrollOffsetChanged += ImageViewer_ScrollOffsetChanged;
            }
            imageViewer.BackgroundColor     = Color.FromHex("#F5F7FA");
            imageViewer.IsFastScrollEnabled = true;
            imageViewer.Zoom(ControlSizeMode.FitWidth, 1, imageViewer.DefaultZoomOrigin);

            // Helps with debugging of there was a rendering error
            imageViewer.RenderError += (sender, e) =>
            {
                var message = string.Format("Error during render item {0} part {1}: {2}",
                                            e.Item != null ? imageViewer.Items.IndexOf(e.Item) : -1,
                                            e.Part,
                                            e.Error.Message);
                System.Diagnostics.Debug.WriteLine(message);
            };

            _documentViewer.Text.AutoGetText = true;
            _documentViewer.Commands.Run(DocumentViewerCommands.InteractiveAutoPan);

            // Enable the pan/zoom interactive mode only if the scan type is Document and not Text because
            // we want the suer to be able to select text in case of extracted text mode.
            if (scanType == DocumentScanType.Document)
            {
                _documentViewer.Commands.Run(DocumentViewerCommands.InteractivePanZoom);
            }

            // Enable inertia scroll
            ToggleInertiaScroll(true);

            SetDocument(documentPath, scanType);
        }
Exemplo n.º 4
0
        private DocumentViewer _svgViewer = null; //The LEADTOOLS ImageViewer Control to view as SVG
        public MainForm()
        {
            InitializeComponent();

            // Setup the caption for this demo
            Messager.Caption = "C# OCR Screen Capture Demo";
            this.Text        = Messager.Caption;

            #region LEADTOOLS ImageViewer
            // Create the LEADTOOLS ImageViewer
            _imageViewer = new ImageViewer();

            // Add it to the Form
            _splitContainer.Panel1.Controls.Add(_imageViewer);
            // Set the display properties
            _imageViewer.BeginUpdate();
            _imageViewer.Dock                    = DockStyle.Fill;
            _imageViewer.BorderStyle             = System.Windows.Forms.BorderStyle.FixedSingle;
            _imageViewer.Cursor                  = System.Windows.Forms.Cursors.Default;
            _imageViewer.ViewHorizontalAlignment = ControlAlignment.Center;
            _imageViewer.ViewVerticalAlignment   = ControlAlignment.Center;
            _imageViewer.ItemHorizontalAlignment = ControlAlignment.Center;
            _imageViewer.ItemVerticalAlignment   = ControlAlignment.Center;
            // Set the layout
            _imageViewer.ViewLayout = new ImageViewerSingleViewLayout();
            _imageViewer.EndUpdate();
            // Hook up the Mouse Events
            _imageViewer.MouseDown  += new MouseEventHandler(imageViewer_MouseDown);
            _imageViewer.MouseMove  += new MouseEventHandler(imageViewer_MouseMove);
            _imageViewer.MouseUp    += new MouseEventHandler(imageViewer_MouseUp);
            _imageViewer.MouseLeave += new EventHandler(imageViewer_MouseLeave);
            _imageViewer.KeyDown    += new KeyEventHandler(imageViewer_KeyDown);
            _imageViewer.LostFocus  += new EventHandler(imageViewer_LostFocus);
            #endregion LEADTOOLS ImageViewer

            #region LEADTOOLS DocumentViewer
            var createOptions = new DocumentViewerCreateOptions()
            {
                ViewContainer       = _splitContainer.Panel2,
                ThumbnailsContainer = null,
                BookmarksContainer  = null,
                UseAnnotations      = false
            };

            _svgViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
            _svgViewer.View.PreferredItemType    = DocumentViewerItemType.Svg;
            _svgViewer.Text.AutoGetText          = true;
            _svgViewer.View.ImageViewer.KeyDown += ImageViewer_KeyDown;
            _svgViewer.Commands.Run(DocumentViewerCommands.InteractiveSelectText);

            _svgViewer.View.ImageViewer.InteractiveModes.BeginUpdate();
            ImageViewerPanZoomInteractiveMode panZoom = new ImageViewerPanZoomInteractiveMode()
            {
                MouseButtons = MouseButtons.Middle
            };
            _svgViewer.View.ImageViewer.InteractiveModes.Add(panZoom);
            _svgViewer.View.ImageViewer.InteractiveModes.EndUpdate();


            ContextMenu viewerContextMenu = new ContextMenu();
            MenuItem    selectAllMenuItem = new MenuItem("Select All");
            selectAllMenuItem.Click += (s, e) => { _svgViewer.Commands.Run(DocumentViewerCommands.TextSelectAll); };
            viewerContextMenu.MenuItems.Add(selectAllMenuItem);

            MenuItem copyText = new MenuItem("Copy");
            copyText.Click += (s, e) => { _svgViewer.Commands.Run(DocumentViewerCommands.TextCopy); };
            viewerContextMenu.MenuItems.Add(copyText);
            _svgViewer.View.ImageViewer.ContextMenu       = viewerContextMenu;
            _svgViewer.View.ImageViewer.MouseDoubleClick += ImageViewer_MouseDoubleClick;
            #endregion LEADTOOLS DocumentViewer
        }
        // Create the document viewer
        private void InitDocumentViewer(DocumentScanType scanType)
        {
            var createOptions = new DocumentViewerCreateOptions();

            // Set the UI part where the main view is displayed
            createOptions.ViewContainer       = DocumentViewerContainer;
            createOptions.ThumbnailsContainer = ThumbnailsLayout;
            createOptions.UseAnnotations      = true;

            // Now create the viewer
            _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions);
            // Set the user name
            _documentViewer.UserName = Environment.UserName;
            // We prefer SVG viewing (if supported)
            _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg;
            // Set thumbnail viewer options
            ImageViewer thumbnailsImageViewer = _documentViewer.Thumbnails.ImageViewer;

            thumbnailsImageViewer.BackgroundColor             = Color.Transparent;
            thumbnailsImageViewer.ItemHorizontalAlignment     = ControlAlignment.Near;
            thumbnailsImageViewer.ItemVerticalAlignment       = ControlAlignment.Near;
            thumbnailsImageViewer.SelectedItemBackgroundColor = Color.FromRgb(80, 131, 242);

            _documentViewer.Operation += _documentViewer_Operation;

            var imageViewer = _documentViewer.View.ImageViewer;

            imageViewer.BackgroundColor = Color.FromHex("#F5F7FA");
#if LEADTOOLS_V21_OR_LATER
            imageViewer.IsFastScrollGadgetEnabled = true;
#endif // #if LEADTOOLS_V21_OR_LATER
            imageViewer.ViewVerticalAlignment = ControlAlignment.Near;
            imageViewer.ViewBorderThickness   = 0;
            imageViewer.ItemBorderThickness   = 0;
            imageViewer.ImageBorderThickness  = 0;
            imageViewer.Zoom(ControlSizeMode.FitWidth, 1, imageViewer.DefaultZoomOrigin);
            imageViewer.InteractiveService.KeyDown += InteractiveService_KeyDown;

            // By default, document viewer has 11 interactive modes added and we don't need them all in our document viewer page.
            // So remove them all exception PanZoom, SelectText and Annotations interactive modes.
            ImageViewerPanZoomInteractiveMode panZoomMode = null;
            var panZoomModes = imageViewer.InteractiveModes.Where(mode => mode.GetType() == typeof(ImageViewerPanZoomInteractiveMode) && (mode as ImageViewerPanZoomInteractiveMode).EnablePan && (mode as ImageViewerPanZoomInteractiveMode).EnablePinchZoom);
            if (panZoomModes != null && panZoomModes.Count() > 0)
            {
                panZoomMode = panZoomModes.ElementAt(0) as ImageViewerPanZoomInteractiveMode;
            }

            DocumentViewerSelectTextInteractiveMode selectTextMode = null;
            var selectTextModes = imageViewer.InteractiveModes.Where(mode => mode.GetType() == typeof(DocumentViewerSelectTextInteractiveMode));
            if (selectTextModes != null && selectTextModes.Count() > 0)
            {
                selectTextMode = selectTextModes.ElementAt(0) as DocumentViewerSelectTextInteractiveMode;
            }

            AnnotationsInteractiveMode annotationsMode = null;
            var annotationsModes = imageViewer.InteractiveModes.Where(mode => mode.GetType() == typeof(AnnotationsInteractiveMode));
            if (annotationsModes != null && annotationsModes.Count() > 0)
            {
                annotationsMode = annotationsModes.ElementAt(0) as AnnotationsInteractiveMode;
            }

            imageViewer.BeginUpdate();
            imageViewer.InteractiveModes.Clear();
            imageViewer.InteractiveModes.Add(annotationsMode);
            imageViewer.InteractiveModes.Add(panZoomMode);
            imageViewer.InteractiveModes.Add(selectTextMode);
            imageViewer.EndUpdate();

            // Helps with debugging of there was a rendering error
            imageViewer.RenderError += (sender, e) =>
            {
                var message = string.Format("Error while rendering item {0} part {1}: {2}",
                                            e.Item != null ? imageViewer.Items.IndexOf(e.Item) : -1,
                                            e.Part,
                                            e.Error.Message);
                System.Diagnostics.Debug.WriteLine(message);
            };

            InitAutomation();

            _documentViewer.Text.AutoGetText = true;
            //_documentViewer.Commands.Run(DocumentViewerCommands.InteractiveAutoPan);

            _documentViewer.View.ImageViewer.ScrollOffsetChanged -= ImageViewer_ScrollOffsetChanged;
            if (scanType == DocumentScanType.Document)
            {
                _documentViewer.View.ImageViewer.ScrollOffsetChanged += ImageViewer_ScrollOffsetChanged;
            }

            // If the scan type is Document enable the pan/zoom interactive mode by default otherwise (Text scan type) enable select text interactive mode by default.
            if (scanType == DocumentScanType.Document)
            {
                _documentViewer.Commands.Run(DocumentViewerCommands.InteractivePanZoom);
                _activeInteractiveMode = DocumentViewerCommands.InteractivePanZoom;
            }
            else
            {
                _activeInteractiveMode = DocumentViewerCommands.InteractiveSelectText;
            }

            UpdateUIState();

            // Enable inertia scroll
            ToggleInertiaScroll(false);
        }