The ASP.NET Document Viewer offers a mechanism to be notified of events during the Document Viewing session. In order to be notified of these events and take appropriate action you need to extend the abstract class ServerEventsHandler and override the necessary methods to provide your handler implementation. This abstract class is present under the Gnostice.Controls.ASP namespace. The server searches for the first available implementation of this class and calls on the methods of it for notification. The code snippet shown below demonstrates an example of this.
For more details about server side preferences that can be set in the OnServerStart event please see the topic on Server side preferences.
using Gnostice.Controls.ASP;
public class MyServerEventsHandler : ServerEventsHandler
{
// The event arguments for all methods below have the following common properties
// HttpContext - instance of HttpContext class for the current request
// Method called when the server starts up
public override void OnServerStart(OnServerStartEventArgs serverStartEventArgs)
{
// serverStartEventArgs.ViewerPreferences contains the preferences for the viewer
// The preferences need to be set when the server starts up and they cannot be
// changed after that
var viewerPreferences = serverStartEventArgs.ViewerPreferences;
// Set rendering preferences
viewerPreferences.Rendering.ViewingDPI = 128;
viewerPreferences.Rendering.PrintingDPI = 128;
// Set allowed file operations
viewerPreferences.FileOperations.AllowUpload = true;
viewerPreferences.FileOperations.AllowDownload = true;
viewerPreferences.FileOperations.AllowDownloadAs = true;
viewerPreferences.FileOperations.AllowSave = true;
viewerPreferences.FileOperations.AllowPrinting = true;
// Set interactivity preferences
viewerPreferences.Interactivity.AllowFormFilling = true;
viewerPreferences.Interactivity.AllowAnnotations = true;
viewerPreferences.Interactivity.AllowSigning = true;
// Set digitization (OCR) preferences
viewerPreferences.Digitization.Enabled = true;
viewerPreferences.Digitization.RecognizeLanguages = "eng+fra";
}
// Method called before the document is loaded
public override void BeforeDocumentLoad(BeforeDocumentLoadEventArgs documentLoadEventArgs)
{
// Read-only property that contains a unique ID assigned to every loaded document
// This identifier can be used to keep track of the document during the current session
var documentId = documentLoadEventArgs.DocumentId;
}
// Method called to get the name of the user viewing currently using the app
public override void NeedUsername(NeedUsernameEventArgs userNameEventArgs)
{
// Read-only property that contains a unique ID assigned to every loaded document
// This identifier can be used to keep track of the document during the current session
var documentId = userNameEventArgs.DocumentId;
// Writable property that contains the user name to set for annotations
userNameEventArgs.UserName = "Alice";
}
// Method called to get the signatures previously stored for the current user
public override void NeedUserSignatures(NeedUserSignaturesEventArgs userSignaturesEventArgs)
{
// Saved user signatures can be supplied in the userSignaturesEventArgs.UserSignatures collection
}
// Method called after the document has been updated and saved in to a stream
public override void AfterDocumentSave(AfterDocumentSaveEventArgs documentSaveEventArgs)
{
// Read-only property that contains a unique ID assigned to every loaded document
// This identifier can be used to keep track of the document during the current session
var documentId = documentSaveEventArgs.DocumentId;
// Read-only property that contains the stream of the updated document
var savedDocStream = documentSaveEventArgs.DocStream;
// Read-only property that contains the user created signatures that can be saved for use later
var userSignatures = documentSaveEventArgs.UserSignatures;
}
}
|