←Select platform

DocumentViewer Class


The DocumentViewer class is the main class used by the document viewer.

public class DocumentViewer : IDisposable 
   ref class DocumentViewer 

The Document Viewer uses LEADTOOLS Raster and Documents support, Caching, SVG, OCR, Annotations, and Image Viewer technologies to create applications that can view, edit, and modify any type of document on the desktop or web with a minimal amount of code.

DocumentViewer is the main class used by the document viewer. It is not a control itself: instead, it uses the parent containers provided by the user to create the necessary UI controls. These containers are native controls in the calling platform (for example, native Controls in Windows Forms and DIV elements in HTML/JavaScript).

The DocumentViewer has the following parts:

  1. View: The main content of the document is viewed here. This part is optional.

  2. Thumbnails: The thumbnails of the pages are viewed here. This part is optional.

  3. Bookmarks: The bookmarks and table of contents for the document are added, viewed, and manipulated here. This part is optional.

  4. Annotations: The annotations toolbar and the objects list are added, viewed, and manipulated here. This part is optional.

  5. Application User Interface: The remaining parts are the UI elements of the user application (they are not part of the document viewer). These are typically standard menu and toolbar items tied to document viewer commands.

Use DocumentViewerFactory.CreateDocumentViewer to create a new instance of DocumentViewer. Then use SetDocument to set LEADDocument objects for viewing, text search, annotations, and converting. Refer to Using LEADTOOLS Document Viewer for more information.


This example will show how to create a functional DocumentViewer in your Windows Forms application.

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(); 
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"); 
   // 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 
      // 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( 
         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; }); 
               rightPanel.Enabled = e.IsPostOperation; 
      // If we have an OCR engine, use it 
      document.Text.OcrEngine = _ocrEngine; 
      // Set it in the viewer 
      // 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; 
      // 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; 
      // 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; 
      // 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; 
      // 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.SelectedIndexChanged += (sender, e) => 
         var commandName = interactiveComboBox.SelectedItem as string; 
      // 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; 
      var exampleButton = new Button(); 
      exampleButton.Top = interactiveComboBox.Bottom + 2; 
      exampleButton.Name = "exampleButton"; 
      exampleButton.Text = "&Example"; 
      exampleButton.Click += (sender, e) => Example(exampleButton); 
   private void Example(Button exampleButton) 
      // Add the example code here 
      Console.WriteLine(this + " Ready"); 

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.