←Select platform

DocumentViewerThumbnails Class

Summary

Manages the thumbnails in this document viewer.

Syntax
C#
C++/CLI
public class DocumentViewerThumbnails : IDisposable 
public: 
   ref class DocumentViewerThumbnails 
Remarks

DocumentViewerThumbnails can be accessed by the Thumbnails property of DocumentViewer.

This class manages the thumbnail image of the pages in the current LEADDocument set in the document viewer.

The class creates an instance of ImageViewer for viewing the thumbnails. The thumbnail images are loaded in a background thread to keep the application user interface responsive.

The class also handles the user interactions with the thumbnails, such as clicking on a thumbnail to move the view to the specified page.

When the Document Viewer is created

If the value of DocumentViewerCreateOptions.ThumbnailsContainer is null, then thumbnails support is not required by the application and DocumentViewer.Thumbnails will be null and should not be used.

Otherwise, the following occurs:

  1. A new instance of DocumentViewerThumbnails is created and set in the DocumentViewer.Thumbnails property.

  2. A new instance of the ImageViewer control is created and is added as a child control to DocumentViewerCreateOptions.ThumbnailsContainer. This image viewer will be used to view the thumbnail image of the pages when an LEADDocument is set in the viewer. This control can be accessed by using ImageViewer property of this class. Refer to the property for information on how this ImageViewer is initialized.

When the Document Viewer is destroyed

  1. The ImageViewer control is removed from the parent ThumbnailsContainer.

  2. All resources are freed.

When a new Document is set

The following occurs when a new LEADDocument object is set in the DocumentViewer using DocumentViewer.SetDocument. The following is performed if a previous document was set in the document viewer:

  1. The background thread is stopped if it is still loading.

  2. The items for the previous document are removed from ImageViewer by calling ImageViewer.Items.Clear.

If the new document set is null (the application just closed this document) then no further action is required. If a new document object is set, then the following is performed:

  1. The recommended thumbnail pixel size is obtained from the new document DocumentImages.ThumbnailPixelSize and set in the ImageViewer.ItemSize property.

  2. An ImageViewerItem is created for each page in the document. The value of ImageViewerItem.ImageSize is calculated from the DocumentPage.Size value of each page and the thumbnail size to maintain the correct aspect ratio. The item’s Text is updated with the string "Page number" and the item is added to the viewer control. The item is "empty" and does not contain image data. This is updated in the next step.

  3. A background thread is created to load the thumbnail images. This is done to keep the application user interface responsive and optimize performance. The thread keeps track of the scroll position in ImageViewer and loads the thumbnails of the items currently visible. The thumbnails are obtained from the document using DocumentPage.GetThumbnailImage. When an image is retrieved, it is set in ImageViewerItem.Image. This is repeated till the images for all thumbnail are obtained. The value of IsLoading can be used to determine whether the background thread is still loading thumbnails.

  4. The Operation event occurs while the background worker is loading the thumbnails. Refer to Document Viewer Operations for the specific details and how to customize the behavior.

Operation

DocumentViewerThumbnails handles the following:

  • When the user clicks on the thumbnail image of a page, DocumentViewer.GotoPage is called to move the view to the specific page.

  • If annotations is used, then the container for each page is rendered on the corresponding thumbnail item and are updated live as the user modifies the annotation objects. This performed using ImageViewer.PostRenderItem.

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Document; 
using Leadtools.Document.Viewer; 
using Leadtools.Codecs; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
 
 
public void DocumentViewer_Example() 
{ 
   // New Form to be used as our application 
   var form = new MyForm(); 
   form.ShowDialog(); 
} 
 
class MyForm : Form 
{ 
   public MyForm() 
   { 
      this.Size = new Size(800, 800); 
      this.Text = "LEADTOOLS Document Viewer Example"; 
   } 
 
   protected override void OnLoad(EventArgs e) 
   { 
      if (!DesignMode) 
      { 
         // Init OCR. This is optional and not required for the PDF document we are loading. 
         // But if image documents are loaded and text functionality is used, then we need OCR 
         _ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD); 
         _ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime"); 
 
         Init(); 
      } 
 
      base.OnLoad(e); 
   } 
 
   // Our document viewer instance 
   private DocumentViewer _documentViewer; 
 
   // Optional OCR engine to use in the example 
   private IOcrEngine _ocrEngine; 
 
   private void Init() 
   { 
      // Initialize the user interface 
      InitUI(); 
 
      // Init the cache. This is optional, but it can speed up viewing of large documents 
      // if not needed, remove this section 
      DocumentFactory.Cache = new FileCache(); 
 
      // Init the document viewer, pass along the panels 
      var createOptions = new DocumentViewerCreateOptions 
      { 
         // The middle panel for the view 
         ViewContainer = this.Controls.Find("middlePanel", false)[0], 
         // The left panel for the thumbnails 
         ThumbnailsContainer = this.Controls.Find("leftPanel", false)[0], 
         // The right panel is for bookmarks 
         BookmarksContainer = this.Controls.Find("rightPanel", false)[0], 
         // Not using annotations for now 
         UseAnnotations = false 
      }; 
 
      // Create the document viewer 
      _documentViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions); 
 
      // We prefer SVG viewing 
      _documentViewer.View.PreferredItemType = DocumentViewerItemType.Svg; 
 
      // Load a document 
      var fileName = @"C:\LEADTOOLS22\Resources\Images\Leadtools.pdf"; 
      var document = DocumentFactory.LoadFromFile( 
         fileName, 
         new LoadDocumentOptions { UseCache = DocumentFactory.Cache != null }); 
 
      _documentViewer.Operation += (sender, e) => 
      { 
         if (e.Operation == DocumentViewerOperation.LoadingBookmarks) 
         { 
            // Disable the bookmarks when we are loading, enable when we are done 
            var rightPanel = this.Controls.Find("rightPanel", true)[0]; 
            if (rightPanel.InvokeRequired) 
            { 
               rightPanel.Invoke((MethodInvoker)delegate { rightPanel.Enabled = e.IsPostOperation; }); 
            } 
            else 
            { 
               rightPanel.Enabled = e.IsPostOperation; 
            } 
         } 
      }; 
 
      // If we have an OCR engine, use it 
      document.Text.OcrEngine = _ocrEngine; 
 
      // Set it in the viewer 
      _documentViewer.SetDocument(document); 
 
      // Run pan/zoom 
      var interactiveComboBox = this.Controls.Find("interactiveComboBox", true)[0] as ComboBox; 
      interactiveComboBox.SelectedItem = DocumentViewerCommands.InteractivePanZoom; 
   } 
 
   private void InitUI() 
   { 
      // Add a panel on the left for the document viewer thumbnails part 
      var leftPanel = new Panel(); 
      leftPanel.Name = "leftPanel"; 
      leftPanel.Width = 200; 
      leftPanel.Dock = DockStyle.Left; 
      leftPanel.BackColor = Color.Gray; 
      leftPanel.BorderStyle = BorderStyle.FixedSingle; 
      this.Controls.Add(leftPanel); 
 
      // Add a panel to the right, this will work for the bookmarks or annotations part 
      var rightPanel = new Panel(); 
      rightPanel.Name = "rightPanel"; 
      rightPanel.Width = 200; 
      rightPanel.Dock = DockStyle.Right; 
      rightPanel.BackColor = Color.LightBlue; 
      rightPanel.BorderStyle = BorderStyle.FixedSingle; 
      this.Controls.Add(rightPanel); 
 
      // Add a panel to fill the rest, for the document viewer 
      var middlePanel = new Panel(); 
      middlePanel.Name = "middlePanel"; 
      middlePanel.BackColor = Color.DarkGray; 
      middlePanel.BorderStyle = BorderStyle.None; 
      middlePanel.Dock = DockStyle.Fill; 
      this.Controls.Add(middlePanel); 
 
      // Add a top panel to host our application controls 
      var topPanel = new Panel(); 
      topPanel.Name = "topPanel"; 
      topPanel.Height = 100; 
      topPanel.Dock = DockStyle.Top; 
      topPanel.BorderStyle = BorderStyle.FixedSingle; 
      this.Controls.Add(topPanel); 
 
      middlePanel.BringToFront(); 
 
      // Add buttons for the UI 
 
      // Combo box for interactive modes 
      var interactiveComboBox = new ComboBox(); 
      interactiveComboBox.Name = "interactiveComboBox"; 
      interactiveComboBox.DropDownStyle = ComboBoxStyle.DropDownList; 
      // The command names for the items so we can just run them 
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractivePanZoom); 
      interactiveComboBox.Items.Add(DocumentViewerCommands.InteractiveSelectText); 
      interactiveComboBox.SelectedIndexChanged += (sender, e) => 
      { 
         var commandName = interactiveComboBox.SelectedItem as string; 
         _documentViewer.Commands.Run(commandName); 
      }; 
      topPanel.Controls.Add(interactiveComboBox); 
 
      // Generic label for information used by the examples 
      var infoLabel = new Label(); 
      infoLabel.Name = "infoLabel"; 
      infoLabel.Text = "Info..."; 
      infoLabel.AutoSize = false; 
      infoLabel.Width = 400; 
      infoLabel.Left = interactiveComboBox.Right + 20; 
      topPanel.Controls.Add(infoLabel); 
 
      var exampleButton = new Button(); 
      exampleButton.Top = interactiveComboBox.Bottom + 2; 
      exampleButton.Name = "exampleButton"; 
      exampleButton.Text = "&Example"; 
      exampleButton.Click += (sender, e) => Example(exampleButton); 
      topPanel.Controls.Add(exampleButton); 
   } 
 
   private void Example(Button exampleButton) 
   { 
      // Add the example code here 
      Console.WriteLine(this + " Ready"); 
   } 
} 
Requirements

Target Platforms

Help Version 22.0.2023.1.30
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Viewer.WinForms Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.