Document Viewer Operations

The DocumentViewer fires the DocumentViewer.Operation event before and after it performs any operation to allow the user to monitor, modify, or abort the action; as well as update the application's state when an operation is run.

The operation mechanism allows the application to modify the behavior when the action happens through the end-user interaction with the document viewer and not directly by the application calling a method.

The Operation event will receive data of type DocumentViewerOperationEventArgs that contains the following members:

Member Description
Operation DocumentViewerOperation enumeration member that identifies the operation.
IsPostOperation Indicates whether the operation is about to run (false) or that the operation has been run (true).
Data1 First optional generic data object associated with the operation. The type and value of this depends on the operation.
Data2 Second optional generic data object associated with the operation. The type and value of this depends on the operation.
PageNumber Page number associated with this operation. 0 if this operation is for the entire document.
Error The exception object if an error occurred during running of the operation.
Abort Can be set by the application to abort running the application.

Example

When the user clicks the mouse on an entry in the bookmarks container, the DocumentViewer.GotoBookmark method is called internally by the DocumentViewer. The application itself does not initiate the call and without the operation mechanism, it has no way of knowing what the user did. Instead, Operation is called and the application has a chance to log, modify, or even abort the action.

Here are the steps:

  1. The user clicks the entry in the bookmarks container.

  2. Operation fires with the following members:

    Member Value Description
    Operation DocumentViewerOperation.GotoBookmark The operation type indicates what is about to happen. In this case, the DocumentViewer.GotoBookmark method is about to be called.
    IsPostOperation false The action has not occurred yet. The document viewer is informing the application that it is about to call GotoBookmark.
    PageNumber 0 Since this is an operation for the entire document.
    Data1 DocumentBookmark instance This is the DocumentBookmark object being passed to GotoBookmark in Data1. The application can perform any action here, including modifying the behavior based on certain bookmarks.
    Data2 null Not used.
    Error null Ignored. Error is never set to a value when IsPostOperation is false. To action has happened yet to throw an error.
    Abort false The application has the chance to gracefully abort this action. This can done as a result of prompting the user or to perform a custom action and override the default behavior of the operation.
  3. When the event returns to the document viewer, it checks the value of Abort, and if it is not false, it will proceed to call GotoBookmark using the bookmark object in Data1.

  4. After the method returns, the Operation event fires again with the following members:

    Member Value Description
    Operation DocumentViewerOperation.GotoBookmark Same operation type as from before, indicating the action that just happened
    IsPostOperation true The action has run. The document viewer is informing the application that GotoBookmark had run and the contents of the bookmark had been applied
    PageNumber 0 Since this is an operation for the entire document
    Data1 DocumentBookmark instance The same DocumentBookmark object passed to GotoBookmark
    Data2 null Not used
    Error null or a value If this value is null, then the operation was performed successfully; otherwise, it will contain an exception object with the error details. The application can use this to show an error message to the user
    Abort Not used The operation has run and it cannot be aborted anymore

Operations

The following is a list of the document viewer operations, when they occur and the value of Data1 and Data2. All the operations are members of the DocumentViewerOperation enumeration that are separated into logical categories below.

Command Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
RunCommand Commands is running any of the built-in or custom commands DocumentViewerCommand object being run The optional value passed to DocumentViewerCommands.Run Not used (0) Setting Abort to true will cancel running the command The command is run

DocumentViewer Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
SetDocument DocumentViewer.SetDocument is called The new LEADDocument object passed to the method The old LEADDocument, if any Not used (0) Setting Abort to true will cancel replacing the new document in the viewer The document is set in the viewer
DetachFromDocument DocumentViewer.SetDocument is called and a current DocumentViewer.Document must be removed. The old LEADDocument, if any The new LEADDocument object passed to the method Not used (0) Setting Abort to true will cancel replacing the new document in the viewer The old LEADDocument is detached but still set to DocumentViewer.Document
AttachToDocument DocumentViewer.SetDocument is called and a new DocumentViewer.Document must be bound. The new LEADDocument object passed to the method The old LEADDocument, if any Not used (0) Setting Abort to true will have no effect The document is set in the viewer
GotoPage DocumentViewer.GotoPage is being used as the result of the user clicking on the thumbnails container Not used Not used Page number Setting Abort to true will leave the current page as is The view moves to the new page
PagesAdded User added pages to the LEADDocument object in the DocumentViewer The 0-based starting index of the first page added A collection of DocumentPage objects being added

Not used (0)

Undefined behavior: Setting Abort to true will cancel adding to the viewer only and the document and viewer will be out of sync. The pages are added to the viewer. The view, thumbnails, annotations, text and bookmarks parts of the viewer will be updated.
PagesRemoved User removed pages from the LEADDocument object in the DocumentViewer The 0-based start index of the first page removed A collection of DocumentPage objects being removed

Not used (0)

Undefined behavior: Setting Abort to true will cancel removing from the viewer only and the document and viewer will be out of sync. The pages are removed from the viewer. The view, thumbnails, annotations, text and bookmarks parts of the viewer are be updated.

View Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
GetPage View virtualizer is calling DocumentPage.GetImage or DocumentPage.GetSvg to obtain the image data for a page that has come into view null when IsPostOperation is false

The image data when IsPostOperation is true

Not used Page number Setting Abort to true will cancel this operation and the image data of this page not be used in the view The page image data is updated
RenderItemPlaceholder View virtualizer is rendering the place holder of a page that does not have its image data loaded. Default behavior is rendering the text "Loading..." on the page item in ImageViewer using ImageViewerRenderEventArgs set in Data1 ImageViewerRenderEventArgs that contains the rendering context to be used Not used Page number Setting Abort to true will cancel the default behavior. Usually applications use this to perform custom rendering of place holders The default behavior of rendering "Loading..." is performed
RenderViewPage View is rendering a DocumentPage When IsPostOperation is true, a boolean to indicate whether the render was internally canceled because a new render was queued; otherwise, not used Not used Page number Setting Abort to true will not cancel the render. The DocumentPage is fully rendered
RunLink The user clicked a link on a page using DocumentViewerPageLinksInteractiveMode and DocumentViewer.RunLinkTarget is about to be called DocumentLink object. RunLinkTarget handles link targets that are locations in the same document DocumentLinkType.TargetPage. If the value of LinkType is DocumentLinkType.Value, then the document viewer will not perform any action. The application can use this operation to check for this value and then custom handle DocumentLink.Value - for example, by checking whether it is a hyperlink and starting a web browser instance pointing to it The InteractiveEventArgs containing the mouse or touch current position and button status. Page number Setting Abort to true will cancel this operation and the link is not run DocumentViewer.RunLinkTarget is called
HoverLink The user has hovered the mouse over (entered) or hovered out of (left) a link area on a page using DocumentViewerPageLinksInteractiveMode DocumentLink object if the mouse is over a link or null if the mouse is not over any links. The application can use this operation to show rich user experience such as displaying a tool tip with the link's value. The InteractiveEventArgs containing the mouse or touch current position and button status. Page number Setting Abort to true will cancel this Nothing
ItemTypeChanged When a new document is set to the viewer and DocumentViewerView.PreferredItemType cannot be used, the DocumentViewerView.ItemType will be set to a new value. The LEADTOOLS Document Viewer uses this value to update the View As Image and View As SVG menu items New value for DocumentViewerView.ItemType Not used Not used (0) Setting Abort to true will cancel this operation and the item type is not changed. The item type is changed.
PageRotate When the user rotates one or more pages using RotatePages. Not used Not used Page number Setting Abort to true will cancel this operation and the page will not be rotated. The page is rotated.
PageDisabled When the user marks a page as disabled using DisablePages. Not used Not used Page number Setting Abort to true will cancel this operation and the page will not be effected. The page is marked as disabled.
PageEnabled When the user marks a page as enabled using EnablePages. Not used Not used Page number Setting Abort to true will cancel this operation and the page will not be effected. The page is marked as enabled.
PageEnabledDisabled When the user is marking one or more pages as enabled or disabled using EnablePages or DisablePages. Not used Not used Array of page numbers Setting Abort to true will cancel this operation and the pages will not be effected. The pages are enabled or disabled.
CurrentPageNumberChanged When the [DocumentViewer.CurrentPageNumber] (used in applications to reference the page number to which certain commands will be applied) is changing. An instance of [CurrentPageNumberChangeData] describing the change Not used Not used (0) Setting Abort to true will cancel this operation and the [DocumentViewer.CurrentPageNumber] will not change. [DocumentViewer.CurrentPageNumber] is updated.

Thumbnails Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
LoadingThumbnails Thumbnails is starting the background thread to get the thumbnail images from the document Not used Not used Not used (0) Setting Abort to true will cancel starting the thread and the thumbnails will not be loaded All thumbnails are loaded and the background thread exists. DocumentViewerThumbnails.IsLoading will be false.
GetThumbnail Thumbnails background thread is calling DocumentPage.GetThumbnailImage for a page Not used when IsPostOperation is false

The thumbnail image when IsPostOperation is true

Not used Page number Setting Abort to true will cancel this operation and the page will not have an image associated with it in the thumbnails container The page thumbnail image is updated
RenderThumbnailPage Thumbnails is rendering a DocumentPage When IsPostOperation is true, a boolean to indicate whether the render was internally canceled because a new render was queued; otherwise, not used Not used Page number Setting Abort to true will not cancel the render. The DocumentPage is fully rendered

Bookmarks Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
LoadingBookmarks Bookmarks is starting the background thread to parse the document and get the bookmark items Not used Not used Not used (0) Setting Abort to true will cancel starting the thread and the bookmarks will not be parsed All bookmarks are parsed and the background thread exists. DocumentViewerBookmarks.IsLoading will be false.
GotoBookmark DocumentViewer.GotoBookmark is being called either directly or as a result of the user clicking an item in the bookmarks container DocumentBookmark object Not used Not used (0) Setting Abort to true will cancel the operation and the bookmarks target will not be applied The bookmark target is applied

Annotations Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
LoadingAnnotations Annotations is starting the background thread to load the annotation containers for each page from the document Not used Not used Not used (0) Application must disable all of the annotations user interface until CreateAutomation occurs.

Setting Abort to true will cancel starting the thread and the annotation containers will not be loaded. DocumentViewerAnnotations.IsLoading will be true

All the annotation containers are loaded and read. CreateAutomation operation will occur next. DocumentViewerAnnotations.IsLoading will be false
GetAnnotations Annotations background thread is calling DocumentPage.GetAnnotations for a page

null when IsPostOperation is false

The annotation container when IsPostOperation is true

Not used Page number Setting Abort to true will cancel this operation and the page will not have an annotation container associated with it The annotations container for the page is saved internally
CreateAutomation Annotations has finished loading the annotation containers for all the pages and is about to create the Automation object

null when IsPostOperation is false

AnnAutomation object when IsPostOperation is true

Not used Not used (0) Setting Abort to true will cancel creating the Automation object and annotations automation support will not work The Automation object has been created, the annotations containers for the pages are added to it and is ready to use. Application must enable the annotations user interface elements and use AnnAutomation events if needed
DestroyAutomation The current LEADDocument object in the viewer has been replaced or set to null AnnAutomation object when IsPostOperation is false

null when IsPostOperation is true

Not used Not used (0) Application must unhook all the events subscribed in CreateAutomation and the annotations user interface elements must be disabled.

Setting Abort to true will cancel the operation and the automation object wil not be destroyed

AnnAutomation is destroyed
AutomationStateChanged The current designer or user mode of the AnnAutomation has been changed Not used Not used Not used (0) Cannot be aborted The application can check the values of AnnAutomation and update the user interface element

Text Operations

Operation Occurs Data1 Data2 PageNumber IsPostOperation false action IsPostOperation true action
GetText Text is calling DocumentPage.GetText to get the DocumentPageText object for a page

null when IsPostOperation is false

The DocumentPageText object when IsPostOperation is true

Not used Page number Setting Abort to true will cancel getting the text for the page.

Application can show a busy dialog to the user and disable the user interface

Application can remove the busy dialog and re-enable the user interface. All text operations for this page are available now
TextSelectionChanged The selected text in the document is changing. Not used Not used Not used (0) Setting Abort to true will cancel changing the document text selection Document viewer de-selects the annotations objects since only this or the text can be selected at one time
PageTextSelectionChanged The selected text in a page has changed Not used Not used Page number Setting Abort to true will cancel changing the page text selection Document viewer will invalidate the page in the View to highlight the selected text
RenderSelectedText The selected text of a page is highlighted on the View ImageViewerRenderEventArgs containing the target context to use for highlighting the text A list of DocumentViewerTextItem that contains the new selected text items Page Number Setting Abort to true will cancel the operation and the default action does not occur. Application can use this to perform custom rendering of the selected text The selected text is highlighted on the page
SelectedTextToReviewObject The user has drawn a new AnnTextReviewObject derived annotation object on a page Object that derives from AnnTextReviewObject Not used Page Number Setting Abort to true will cancel the operation and the default action will not occur. The selected text item rectangles are set in the object. The object is added to the page annotation container and is selected
FindText

DocumentViewerText.Find has begun or has been completed for a given page or all pages

A clone of the provided DocumentViewerFindText options

The results of the search, which will be null if isPostOperation is false or there are no matches

Page Number

Setting Abort to true will cancel the operation and the default action does not occur

Search has completed for the page(s)

RenderFoundText

A repaint occurs after a DocumentViewerText.Find completes successfully with results

ImageViewerRenderEventArgs containing the target context to use for rendering the found text

A list of DocumentViewerTextItem that contains the rendering found text items

Page Number

Setting Abort to true will cancel the operation and the default action does not occur

The found text is rendered on the page

See Also

Using LEADTOOLS Document Viewer

Document Viewer Commands

Document Library Features

Loading Using LEADTOOLS Document Library

Creating Documents with LEADTOOLS Document Library

Document Toolkit and Caching

Using LEADTOOLS Document Converter

Document View and Convert Redaction

DocumentViewer.CurrentPageNumber

CurrentPageNumberChangeData

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

LEADTOOLS Imaging, Medical, and Document

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.