operation Event

Summary

Occurs when an operation is invoked inside this document viewer.

Syntax
TypeScript
JavaScript
Object.defineProperty(DocumentViewer.prototype,'operation',get:function(),set:function(value))
operation:LeadEvent;
Event Data
Parameter Type Description
sender var The source of the event.
e DocumentViewerOperationEventArgs The event data.
Remarks

TheOperationevent occurs anytime the document viewer is performing an operation (for example, when rendering the place holder of a page on theView, or when a new annotation object is added, etc.).

EachOperationevent fires twice. The first time the value ofDocumentViewerOperationEventArgs.IsPostOperationis set tofalseto indicate that the operation is about to happen. The second timeDocumentViewerOperationEventArgs.IsPostOperationis set totrueto indicate that the operation is completed.

The operation type is stored inOperation. WhenIsPostOperationisfalse, some operations allow the user to change the behavior or abort the operation.

Refer toDocument Viewer Operationsfor a detailed list of all document viewer operations.

Example

In this example, clicking the example button will add an intercept callback that will prevent clicked links from being run.

Operation.ts
ViewerInitializer.ts
Operation.js
ViewerInitializer.js
Operation.html
examples.css
import{ ViewerInitializer } from"../utilities/ViewerInitializer";exportclassOperationTSExample {publicrun = () => {newViewerInitializer(this.addOperationEvent);}addOperationEvent = (documentViewer: lt.Document.Viewer.DocumentViewer) => {// Add a callback for when the user clicks a link (bookmark on the page, for example)documentViewer.operation.add((sender:any, e: lt.Document.Viewer.DocumentViewerOperationEventArgs) => {// When the user clicks a link and we're going to start running the link...if(e.operation == lt.Document.Viewer.DocumentViewerOperation.runLink && !e.isPostOperation) {constlink = e.data1;if(link) {// Cancel the operatione.abort =true;// Show a messagelet message ="Link will be ignored!";if(link.bounds) {message +="\nbounds: "+ link.bounds.x +", "+ link.bounds.y +", "+ link.bounds.width +", "+ link.bounds.bottom;}if(link.target && link.target.pageNumber) {message +="\ntarget page: "+ link.target.pageNumber;}alert(message);}}});}}
exportclassViewerInitializer {privatecallback: (viewer: lt.Document.Viewer.DocumentViewer) =>void=null;constructor(callback?: (viewer: lt.Document.Viewer.DocumentViewer) =>void) {this.callback = callback;this.init();}publicstaticshowServiceError = (jqXHR, statusText, errorThrown) => {alert('Error returned from service. See the console for details.')constserviceError = lt.Document.ServiceError.parseError(jqXHR, statusText, errorThrown);console.error(serviceError);}privateinit = () => {this.initFactory();this.testConnection();}privateinitFactory = () => {lt.RasterSupport.setLicenseUri('https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt','EVAL',null);// To communicate with the DocumentsService, it must be running!// Change these parameters to match the path to the service.lt.Document.DocumentFactory.serviceHost ='http://localhost:40000';lt.Document.DocumentFactory.servicePath ='';lt.Document.DocumentFactory.serviceApiPath ='api';}privatetestConnection = () => {constserviceStatus = document.getElementById('serviceStatus');serviceStatus.innerHTML ='Connecting to service: '+ lt.Document.DocumentFactory.serviceUri;lt.Document.DocumentFactory.verifyService().done((serviceData) => {serviceStatus.innerHTML ='Service connection verified!';this.createDocumentViewer();}).fail((jqXHR, statusText, errorThrown) => {serviceStatus.innerHTML ='Service connection unavailable.';ViewerInitializer.showServiceError(jqXHR, statusText, errorThrown);});}privatecreateDocumentViewer = () => {// Initialize the user interfaceconstinteractiveSelect = document.getElementById('interactiveSelect');constpanZoomOption = document.createElement('option');panZoomOption.innerHTML ='Pan / Zoom';panZoomOption.value = lt.Document.Viewer.DocumentViewerCommands.interactivePanZoom;interactiveSelect.appendChild(panZoomOption);const文本Option = document.createElement('option');文本Option.value = lt.Document.Viewer.DocumentViewerCommands.interactiveSelectText;文本Option.innerHTML ='Select Text';interactiveSelect.appendChild(textOption);let documentViewer: lt.Document.Viewer.DocumentViewer =null;interactiveSelect.onchange = (e) => documentViewer.commands.run((e.target as HTMLSelectElement).value,null);constannotationsSelect = document.getElementById('annotationsSelect');constannSelectOption = document.createElement('option');annSelectOption.innerHTML ='Select Annotation';annSelectOption.value = lt.Annotations.Engine.AnnObject.selectObjectId.toString();annotationsSelect。appendChild(annSelectOption);constannLineOption = document.createElement('option');annLineOption.innerHTML ='Line Object';annLineOption.value = lt.Annotations.Engine.AnnObject.lineObjectId.toString();annotationsSelect。appendChild(annLineOption);constannRectOption = document.createElement('option');annRectOption.innerHTML ='Rectangle Object';annRectOption.value = lt.Annotations.Engine.AnnObject.rectangleObjectId.toString();annotationsSelect。appendChild(annRectOption);annotationsSelect。onchange = (e) => {constvalue = +(e.currentTarget as HTMLSelectElement).value;documentViewer.annotations.automationManager.currentObjectId = value;}// Init the document viewer, pass along the panelsconstcreateOptions =newlt.Document.Viewer.DocumentViewerCreateOptions();// We are not going to use elements mode in this examplecreateOptions.viewCreateOptions.useElements =false;createOptions.thumbnailsCreateOptions.useElements =false;// The middle panel for the viewcreateOptions.viewContainer = document.getElementById('viewer');// The left panel for the thumbnailscreateOptions.thumbnailsContainer = document.getElementById('thumbnails');// The right panel is for bookmarkscreateOptions.bookmarksContainer = document.getElementById('bookmarks');createOptions.useAnnotations =true;// Create the document viewerdocumentViewer = lt.Document.Viewer.DocumentViewerFactory.createDocumentViewer(createOptions);// We prefer SVG viewingdocumentViewer.view.preferredItemType = lt.Document.Viewer.DocumentViewerItemType.svg;// Create html5 rendering enginedocumentViewer.annotations.automationManager.renderingEngine =newlt.Annotations.Rendering.AnnHtml5RenderingEngine();// Initialize documentViewer annotationsdocumentViewer.annotations.initialize();documentViewer.annotations.automationManager.currentObjectIdChanged.add(function(sender, e) {// When done drawing, the manager will return to the select object; so we need force the annotationsSelect element to return to the select object option(annotationsSelect as HTMLSelectElement).value = sender.currentObjectId;});this.loadDefaultDoc(documentViewer, interactiveSelect as HTMLSelectElement)}privateloadDefaultDoc = (viewer: lt.Document.Viewer.DocumentViewer, interactiveSelect: HTMLSelectElement) => {// Load a PDF documentconsturl ='https://demo.leadtools.com/images/pdf/leadtools.pdf';lt.Document.DocumentFactory.loadFromUri(url,null).done((doc: lt.Document.LEADDocument) => {constready = () => {viewer.setDocument(doc);constpanZoom = lt.Document.Viewer.DocumentViewerCommands.interactivePanZoom;interactiveSelect.value = panZoom;viewer.commands.run(panZoom,null);if(this.callback)this.callback(viewer);}if(doc.isStructureSupported && !doc.structure.isParsed)doc.structure.parse().done(ready).fail(ViewerInitializer.showServiceError);elseready();}).fail(ViewerInitializer.showServiceError);}}
import{ ViewerInitializer } from"../utilities/ViewerInitializer";exportclassOperationJSExample {run = () => {newViewerInitializer(this.addOperationEvent);}addOperationEvent = (documentViewer) => {// Add a callback for when the user clicks a link (bookmark on the page, for example)documentViewer.operation.add((sender, e) => {// When the user clicks a link and we're going to start running the link...if(e.operation == lt.Document.Viewer.DocumentViewerOperation.runLink && !e.isPostOperation) {constlink = e.data1;if(link) {// Cancel the operatione.abort =true;// Show a messagelet message ="Link will be ignored!";if(link.bounds) {message +="\nbounds: "+ link.bounds.x +", "+ link.bounds.y +", "+ link.bounds.width +", "+ link.bounds.bottom;}if(link.target && link.target.pageNumber) {message +="\ntarget page: "+ link.target.pageNumber;}alert(message);}}});}}
exportclassViewerInitializer {constructor(callback) {this.callback = callback;this.init();}staticshowServiceError = (jqXHR, statusText, errorThrown) => {alert("Error returned from service. See the console for details.")constserviceError = lt.Document.ServiceError.parseError(jqXHR, statusText, errorThrown);console.error(serviceError);}init = () => {this.initFactory();this.testConnection();}initFactory = () => {lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt","EVAL",null);// To communicate with the DocumentsService, it must be running!// Change these parameters to match the path to the service.lt.Document.DocumentFactory.serviceHost ="http://localhost:40000";lt.Document.DocumentFactory.servicePath ="";lt.Document.DocumentFactory.serviceApiPath ="api";}testConnection = () => {constserviceStatus = document.getElementById("serviceStatus");serviceStatus.innerHTML ="Connecting to service: "+ lt.Document.DocumentFactory.serviceUri;lt.Document.DocumentFactory.verifyService().done((serviceData) => {serviceStatus.innerHTML ="Service connection verified!";this.createDocumentViewer();}).fail((jqXHR, statusText, errorThrown) => {serviceStatus.innerHTML ="Service connection unavailable.";ViewerInitializer.showServiceError(jqXHR, statusText, errorThrown);});}createDocumentViewer = () => {// Initialize the user interfaceconstinteractiveSelect = document.getElementById("interactiveSelect");constpanZoomOption = document.createElement("option");panZoomOption.innerHTML ="Pan / Zoom";panZoomOption.value = lt.Document.Viewer.DocumentViewerCommands.interactivePanZoom;interactiveSelect.appendChild(panZoomOption);const文本Option = document.createElement("option");文本Option.value = lt.Document.Viewer.DocumentViewerCommands.interactiveSelectText;文本Option.innerHTML ="Select Text";interactiveSelect.appendChild(textOption);let documentViewer =null;interactiveSelect.onchange = (e) => documentViewer.commands.run(e.target.value,null);constannotationsSelect = document.getElementById("annotationsSelect");constannSelectOption = document.createElement("option");annSelectOption.innerHTML ="Select Annotation";annSelectOption.value = lt.Annotations.Engine.AnnObject.selectObjectId.toString();annotationsSelect。appendChild(annSelectOption);constannLineOption = document.createElement("option");annLineOption.innerHTML ="Line Object";annLineOption.value = lt.Annotations.Engine.AnnObject.lineObjectId.toString();annotationsSelect。appendChild(annLineOption);constannRectOption = document.createElement("option");annRectOption.innerHTML ="Rectangle Object";annRectOption.value = lt.Annotations.Engine.AnnObject.rectangleObjectId.toString();annotationsSelect。appendChild(annRectOption);annotationsSelect。onchange = (e) => {constvalue = +e.currentTarget.value;documentViewer.annotations.automationManager.currentObjectId = value;}// Init the document viewer, pass along the panelsconstcreateOptions =newlt.Document.Viewer.DocumentViewerCreateOptions();// We are not going to use elements mode in this examplecreateOptions.viewCreateOptions.useElements =false;createOptions.thumbnailsCreateOptions.useElements =false;// The middle panel for the viewcreateOptions.viewContainer = document.getElementById("viewer");// The left panel for the thumbnailscreateOptions.thumbnailsContainer = document.getElementById("thumbnails");// The right panel is for bookmarkscreateOptions.bookmarksContainer = document.getElementById("bookmarks");createOptions.useAnnotations =true;// Create the document viewerdocumentViewer = lt.Document.Viewer.DocumentViewerFactory.createDocumentViewer(createOptions);// We prefer SVG viewingdocumentViewer.view.preferredItemType = lt.Document.Viewer.DocumentViewerItemType.svg;// Create html5 rendering enginedocumentViewer.annotations.automationManager.renderingEngine =newlt.Annotations.Rendering.AnnHtml5RenderingEngine();// Initialize documentViewer annotationsdocumentViewer.annotations.initialize();documentViewer.annotations.automationManager.currentObjectIdChanged.add(function(sender, e) {// When done drawing, the manager will return to the select object; so we need force the annotationsSelect element to return to the select object optionannotationsSelect。值= sender.currentObjectId;});this.loadDefaultDoc(documentViewer, interactiveSelect)}loadDefaultDoc = (viewer, interactiveSelect) => {// Load a PDF documentconsturl ="https://demo.leadtools.com/images/pdf/leadtools.pdf";lt.Document.DocumentFactory.loadFromUri(url,null).done((doc) => {constready = () => {viewer.setDocument(doc);constpanZoom = lt.Document.Viewer.DocumentViewerCommands.interactivePanZoom;interactiveSelect.value = panZoom;viewer.commands.run(panZoom,null);if(this.callback)this.callback(viewer);}if(doc.isStructureSupported && !doc.structure.isParsed)doc.structure.parse().done(ready).fail(ViewerInitializer.showServiceError);elseready();}).fail(ViewerInitializer.showServiceError);}}
"en">DocViewer Example | DocumentViewer




"stylesheet"type="text/css"href="../css/examples.css">class="container">class="toolbar">class="vcenter push-right">
class="vcenter push-right">for="interactiveSelect">Interactive mode:
class="vcenter push-right">for="annotationsSelect">Annotations objects:
"output"class="vcenter push-right">
"serviceStatus"class="vcenter push-right">
class="docContainer">class="sidepanel"id="thumbnails">
class="centerpanel"id="viewer">class="sidepanel"id="bookmarks">