←Select platform

DocumentViewerView Class

Summary

Manages the main content view in this document viewer

Syntax

C#
VB
C++
public class DocumentViewerView : IDisposable 
Public Class DocumentViewerView 
public: 
   ref class DocumentViewerView 

Remarks

DocumentViewerView can be accessed by the DocumentViewer.View property.

This class manages the main content to view the pages of the current Document set in the document viewer.

The class creates an instance of ImageViewer for viewing the pages. Virtualization is used to load and cache the image data to keep the application user interface responsive, support documents with large number of pages and minimize the resources used. Raster and SVG viewing modes is supported.

The class also handles the user interactions with the pages, such pan, zoom and magnify interactive modes, inertia scrolling, page layouts and fit modes and rendering the annotation containers.

When the Document Viewer is created

  1. A new instance of DocumentViewerView is created and set in the DocumentViewer.View property.

  2. A new instance of the ImageViewer control is created and is added as a child control to DocumentViewerCreateOptions.ViewContainer. This image viewer will be used to view the Raster or SVG image data of the pages when an Document 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.

  3. The interactive modes are initialized and added to ImageViewer.InteractiveModes.

When the Document Viewer is destroyed

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

  2. All resources are freed

When a new Document is set

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

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:

  • PreferredItemType is checked, and if SVG viewing is requested then IsSvgViewingPreferred is updated accordingly.

  • An ImageViewerItem is created for each page in the document. The value of ImageViewerItem.ImageSize is set to value of DocumentPage.Size of each page. The item is "empty" and does not contain image data. This is updated in the next step.

  • An internal worker is used to handler loading and caching the image data of the pages in the background to keep the user interface of the application responsive. This worker is also used to minimize the resources used when loading a document with large image data and large number of pages by prioritizing loading the data for visible pages and discarding the data for pages that are no longer used.

  • The Operation event occurs while the virtualizer is loading and discarding image data and when rendering the place holder for pages that do not have their data loaded yet. Refer to Document Viewer Operations for more information on the specific details and how to customize the behavior.

Commands

DocumentViewerView handles the following:

  • All the ImageViewerInteractiveMode created by this part. This includes pan, zoom, and magnify glass as well as the page links, annotations and text selection modes.

  • Multiple ImageViewerViewLayout such as single, vertical, double and horizontal are created and can be used by the view.

  • Rendering of the image data of the pages as well as the current text selection and annotation containers

Refer to Document Viewer Commands and Document Viewer Operations for more information on the above and how to set and customize the behavior.

Example

Start with the example created in DocumentViewer, remove all the code in the Example function and add the code below.

After the user clicks the Example button, we will draw a label for the page number at the bottom of each page.

C#
VB
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Documents; 
using Leadtools.Documents.UI; 
using Leadtools.Codecs; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
 
// Disable the example button, this should only run once 
exampleButton.Enabled = false; 
 
// Get the view 
var view = _documentViewer.View; 
// Get its image viewer 
var imageViewer = view.ImageViewer; 
// Hook to the PostRender 
imageViewer.PostRenderItem += (sender, e) => 
{ 
   // Get the image viewer item for the page 
   var item = e.Item; 
 
   // Get the current rectangle for the image 
   var bounds = imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, false); 
 
   // Build the text we want. The page number is the item index + 1 
   var pageNumber = imageViewer.Items.IndexOf(item) + 1; 
   var text = "Page " + pageNumber.ToString(); 
 
   // Get the image transformation for this item 
   var transform = imageViewer.GetItemImageTransform(e.Item); 
 
   // Apply it to the context 
   var gstate = e.Context.Save(); 
   using (var matrix = new System.Drawing.Drawing2D.Matrix( 
      (float)transform.M11, 
      (float)transform.M12, 
      (float)transform.M21, 
      (float)transform.M22, 
      (float)transform.OffsetX, 
      (float)transform.OffsetY)) 
   { 
      e.Context.MultiplyTransform(matrix); 
   } 
 
   // Render the text at the bottom of the bounds 
   var flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom; 
   var rc = new Rectangle((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height); 
   TextRenderer.DrawText(e.Context, text, imageViewer.Font, rc, Color.White, Color.Black, flags); 
 
   e.Context.Restore(gstate); 
}; 
 
// Invalidate so our changes take effect the first time 
view.Invalidate(); 
Imports Leadtools 
Imports Leadtools.Controls 
Imports Leadtools.Documents 
Imports Leadtools.Documents.UI 
Imports Leadtools.Codecs 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Forms.Ocr 
 
' Disable the example button, this should only run once 
exampleButton.Enabled = False 
 
' Get the view 
Dim view As DocumentViewerView = _documentViewer.View 
' Get its image viewer 
Dim imageViewer As ImageViewer = view.ImageViewer 
' Hook to the PostRender 
AddHandler imageViewer.PostRenderItem, 
   Sub(sender, e) 
      ' Get the image viewer item for the page 
      Dim item As ImageViewerItem = e.Item 
 
      ' Get the current rectangle for the image 
      Dim bounds As LeadRectD = imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, False) 
 
      ' Build the text we want. The page number is the item index + 1 
      Dim pageNumber As Integer = imageViewer.Items.IndexOf(item) + 1 
      Dim text As String = "Page " + pageNumber.ToString() 
 
      ' Get the image transformation for this item 
      Dim transform As LeadMatrix = imageViewer.GetItemImageTransform(e.Item) 
 
      ' Apply it to the context 
      Dim gstate As System.Drawing.Drawing2D.GraphicsState = e.Context.Save() 
      Using matrix As New System.Drawing.Drawing2D.Matrix( 
         CType(transform.M11, Single), 
         CType(transform.M12, Single), 
         CType(transform.M21, Single), 
         CType(transform.M22, Single), 
         CType(transform.OffsetX, Single), 
         CType(transform.OffsetY, Single)) 
         e.Context.MultiplyTransform(matrix) 
      End Using 
 
      ' Render the text at the bottom of the bounds 
      Dim flags As TextFormatFlags = TextFormatFlags.HorizontalCenter Or TextFormatFlags.Bottom 
      Dim rc As New Rectangle(CInt(bounds.X), CInt(bounds.Y), CInt(bounds.Width), CInt(bounds.Height)) 
      TextRenderer.DrawText(e.Context, text, imageViewer.Font, rc, Color.White, Color.Black, flags) 
 
      e.Context.Restore(gstate) 
   End Sub 
 
' Invalidate so our changes take effect the first time 
view.Invalidate() 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents.UI.WinForms Assembly