VintaSoft Imaging .NET SDK 14.0: Documentation for Web developer
In This Topic
    Add web document viewer to an ASP.NET WebForms application
    In This Topic
    This tutorial shows how to create a blank ASP.NET Web application in Visual Studio .NET 2019 and add document viewer (with ability to open images and documents (PDF, DOCX, XLSX), extract/search text, annotate documents) to ASP.NET WebForms application.

    Here are steps, which must be done:
    1. Create a blank ASP.NET WebForms application.

      Open Visual Studio .NET 2019 and create a new project, of ASP.NET Web application type, and configure the project to use .NET Framework 4.7.2:

      Select the "Empty" template for ASP.NET Web application and configure the project to use WebForms:

    2. Server side: Add references to the Vintasoft assemblies to ASP.NET WebForms application.

      Add references to the Vintasoft.Shared.dll, Vintasoft.Imaging.dll, Vintasoft.Imaging.Annotation.dll, Vintasoft.Imaging.Pdf.dll, Vintasoft.Imaging.Office.OpenXml.dll, Vintasoft.Shared.Web.dll, Vintasoft.Imaging.Web.Services.dll, Vintasoft.Imaging.Annotation.Web.Services.dll, Vintasoft.Imaging.Web.Handlers.dll and Vintasoft.Imaging.Annotation.Web.Handlers.dll assemblies from "<SdkInstallPath>\VintaSoft Imaging .NET 14.0\Bin\DotNet4\AnyCPU\" folder in ASP.NET WebForms application.



    3. Server side: Specify drawing engine, which should be used by VintaSoft Imaging .NET SDK for drawing of 2D graphics.

      ASP.NET WebForms application should use System.Drawing library as drawing engine because ASP.NET WebForms application can be used in Windows only.

      Here are steps, which should be made for using System.Drawing engine:
      • Add reference to the Vintasoft.Imaging.Gdi.dll assembly.
      • Open "Default.aspx.cs" file, add code line "Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();" at the beginning of Page_Load method - added code specifies that VintaSoft Imaging .NET SDK should use System.Drawing library for drawing of 2D graphics.

    4. Server side: Create web services, which allow to upload/download file, manage image collection, get information about images, get thumbnails, render image tiles, extract/search text and annotate document.

      • Add the "Handlers" folder to ASP.NET WebForms application.
      • Create web service that allows to upload/download file

        • Press the right mouse button on the "Handlers" folder and select the "Add => Generic handler" menu from context menu
        • Specify the handler name "MyVintasoftFileHandler" and press the "Ok" button
        • Specify that MyVintasoftFileHandler class is derived from VintasoftImaging.Web.HttpHandlers.VintasoftFileHandler class

          Here are C# source codes of MyVintasoftFileHandler class:
          namespace WebApplication1.Handlers
          {
              public class MyVintasoftFileHandler : Vintasoft.Imaging.Web.HttpHandlers.VintasoftFileHandler
              {
              }
          }
          
          
      • Create web service that allows to manage image collection

        • Press the right mouse button on the "Handlers" folder and select the "Add => Generic handler" menu from context menu
        • Specify the handler name "MyVintasoftImageCollectionHandler" and press the "Ok" button
        • Specify that MyVintasoftImageCollectionHandler class is derived from VintasoftImaging.Web.HttpHandlers.VintasoftImageCollectionHandler class

          Here are C# source codes of MyVintasoftImageCollectionHandler class:
          namespace WebApplication1.Handlers
          {
              public class MyVintasoftImageCollectionHandler : Vintasoft.Imaging.Web.HttpHandlers.VintasoftImageCollectionHandler
              {
              }
          }
          
          
      • Create web service that allows to get information about images, get thumbnails, render image tiles, extract/search text

        • Press the right mouse button on the "Handlers" folder and select the "Add => Generic handler" menu from context menu
        • Specify the handler name "MyVintasoftImageHandler" and press the "Ok" button
        • Specify that MyVintasoftImageHandler class is derived from VintasoftImaging.Web.HttpHandlers.VintasoftImageHandler class

          Here are C# source codes of MyVintasoftImageHandler class:
          namespace WebApplication1.Handlers
          {
              public class MyVintasoftImageHandler : Vintasoft.Imaging.Web.HttpHandlers.VintasoftImageHandler
              {
              }
          }
          
          
      • Create web service that allows to annotate images and documents

        • Press the right mouse button on the "Handlers" folder and select the "Add => Generic handler" menu from context menu
        • Specify the handler name "MyVintasoftAnnotationCollectionHandler" and press the "Ok" button
        • Specify that MyVintasoftAnnotationCollectionHandler class is derived from VintasoftImaging.Annotation.Web.HttpHandlers.VintasoftAnnotationCollectionHandler class

          Here are C# source codes of MyVintasoftFileHandler class:
          namespace WebApplication1.Handlers
          {
              public class MyVintasoftAnnotationCollectionHandler :
                  Vintasoft.Imaging.Annotation.Web.HttpHandlers.VintasoftAnnotationCollectionHandler
              {
              }
          }
          
          
    5. Client side: Add JavaScript libraries to the project.

      • Add the "Scripts\" folder to ASP.NET WebForms application if folder does not exist.

      • Copy Vintasoft.Shared.js, Vintasoft.Imaging.js, Vintasoft.Imaging.css, Vintasoft.Imaging.Annotation.js, Vintasoft.Imaging.Annotation.css and Vintasoft.Imaging.DocumentViewer.js files from "<InstallPath>\VintaSoft Imaging .NET 14.0\Bin\JavaScript\" folder into "Scripts\" folder.

      • Specify, which "standard" dialogs (password dialog, print dialog, etc) should be used by web document viewer
        • If web document viewer should use ready-to-use "standard" jQuery UI dialogs:
          • Copy jQuery file into "Scripts\" folder.
            You can use "jquery-3.3.1.min.js" file from "<InstallPath>\VintaSoft Imaging .NET 14.0\Examples\ASP.NET MVC\CSharp\AspNetMvcImagingDemo\Scripts\External\" folder or jQuery file from any other source.
          • Copy jQuery UI files and folders into "Scripts\" folder.
            You can use "jquery-ui.min.js" file and "jquery-ui-css" folder from "<InstallPath>\VintaSoft Imaging .NET 14.0\Examples\ASP.NET MVC\CSharp\AspNetMvcImagingDemo\Scripts\External\" folder or jQuery UI files and folders from any other source.
          • Copy Vintasoft.Imaging.Dialogs.jQueryUI.js and Vintasoft.Imaging.DocumentViewer.Dialogs.jQueryUI.js files from "<InstallPath>\VintaSoft Imaging .NET 14.0\Bin\JavaScript\" folder into "Scripts\" folder.

        • If web document viewer should use custom "standard" dialogs, please read how to create custom "standard" dialogs here.
    6. Client side: Add JavaScript code, which initializes and dispalys document viewer, to the Default web form.

      • Create folder "UploadedImageFiles\SessionID" and copy PDF document "<InstallPath>VintaSoft\Imaging .NET 14.0\Images\VintasoftImagingDemo.pdf" to the folder. This document will be displayed in document viewer.

      • Create the Default web form - file "Default.aspx".
        • Press the right mouse button on the project and select the "Add => WebForm" menu from context menu:


        • Specify "Default" as web form name => created web form will be opened:

      • Add references to the JavaScript files:

        Here is HTML code that adds references to jQuery and Vintasoft JavaScript files:
        <style>
            * {
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                border-collapse: collapse;
            }
        </style>
        
        <link rel="stylesheet" type="text/css" href="Scripts/jquery-ui-css/jquery-ui.min.css">
        <link rel="stylesheet" type="text/css" href="Scripts/Vintasoft.Imaging.css">
        <link rel="stylesheet" type="text/css" href="Scripts/Vintasoft.Imaging.Annotation.css">
        
        <script src="Scripts/jquery-3.3.1.min.js" type="text/javascript"></script>
        <script src="Scripts/jquery-ui.min.js" type="text/javascript"></script>
        
        <script src="Scripts/Vintasoft.Shared.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.Dialogs.jQueryUI.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.Annotation.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.Annotation.Dialogs.jQueryUI.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.DocumentViewer.js" type="text/javascript"></script>
        <script src="Scripts/Vintasoft.Imaging.DocumentViewer.Dialogs.jQueryUI.js" type="text/javascript"></script>
        


      • Add HTML markup (a div-element that will display document viewer) to the web view:

        Here is HTML markup code:
        <form id="form1" runat="server">
            <h1 style="text-align: center">VintaSoft Document Viewer Demo (ASP.NET WebForms)</h1>
            <div id="documentViewerContainer" style="height: 800px"></div>
        </form>
        


      • Add JavaScript code that displays document viewer:

        Here is JavaScript code (with page markup) that displays document viewer:
        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
        
        <!DOCTYPE html>
        
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title>VintaSoft Document Viewer Demo (ASP.NET WebForms)</title>
        
            <style>
                * {
                    -webkit-box-sizing: border-box;
                    box-sizing: border-box;
                    border-collapse: collapse;
                }
            </style>
        
            <link rel="stylesheet" type="text/css" href="Scripts/jquery-ui-css/jquery-ui.min.css">
            <link rel="stylesheet" type="text/css" href="Scripts/Vintasoft.Imaging.css">
            <link rel="stylesheet" type="text/css" href="Scripts/Vintasoft.Imaging.Annotation.css">
        
            <script src="Scripts/jquery-3.3.1.min.js" type="text/javascript"></script>
            <script src="Scripts/jquery-ui.min.js" type="text/javascript"></script>
        
            <script src="Scripts/Vintasoft.Shared.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.Dialogs.jQueryUI.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.Annotation.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.Annotation.Dialogs.jQueryUI.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.DocumentViewer.js" type="text/javascript"></script>
            <script src="Scripts/Vintasoft.Imaging.DocumentViewer.Dialogs.jQueryUI.js" type="text/javascript"></script>
        </head>
        <body>
            <form id="form1" runat="server">
                <h1 style="text-align: center">VintaSoft Document Viewer Demo (ASP.NET WebForms)</h1>
                <div id="documentViewerContainer" style="height: 800px"></div>
            </form>
        
            <script type="text/javascript">
                // set the session identifier
                Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
                // specify web services, which should be used by Vintasoft Web Document Viewer
                Vintasoft.Shared.WebServiceJS.defaultFileService =
                    new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/MyVintasoftFileHandler.ashx");
                Vintasoft.Shared.WebServiceJS.defaultImageCollectionService =
                    new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/MyVintasoftImageCollectionHandler.ashx");
                Vintasoft.Shared.WebServiceJS.defaultImageService =
                    new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/MyVintasoftImageHandler.ashx");
                Vintasoft.Shared.WebServiceJS.defaultAnnotationService =
                    new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/MyVintasoftAnnotationCollectionHandler.ashx");
        
                // create settings for document viewer with annotation support
                let docViewerSettings =
                    new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerSettingsJS("documentViewerContainer", { annotations: true });
        
                // get items of document viewer
                var items = docViewerSettings.get_Items();
        
                // get the main menu of document viewer
                var mainMenu = items.getItemByRegisteredId("mainMenu");
                // if main menu is found
                if (mainMenu != null) {
                    // get items of main menu
                    let mainMenuItems = mainMenu.get_Items();
        
                    // add "Annotation" menu panel to the main menu
                    mainMenuItems.addItem("annotationsMenuPanel");
                }
        
                // get side panel of document viewer
                var sidePanel = items.getItemByRegisteredId("sidePanel");
                // if side panel is found
                if (sidePanel != null) {
                    // get items of side panel
                    var sidePanelItems = sidePanel.get_PanelsCollection();
        
                    // add "Annotations" panel to the side panel
                    sidePanelItems.addItem("annotationsPanel");
        
                    // add "Text selection" panel to the side panel
                    sidePanelItems.addItem("textSelectionPanel");
        
                    // add "Text searh" panel to the side panel
                    sidePanelItems.addItem("textSearchPanel");
                }
        
                // create the document viewer
                var docViewer = new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerJS(docViewerSettings);
        
                // create visual tool that allows to work with annotations, navigate document and select text
                var annotationNavigationTextSelectionTool =
                    docViewer.getVisualToolById("AnnotationVisualTool,DocumentNavigationTool,TextSelectionTool");
                // specify visual tool as mandatory visual tool of document viewer
                docViewer.set_MandatoryVisualTool(annotationNavigationTextSelectionTool);
                // specify visual tool as current visual tool of document viewer
                docViewer.set_CurrentVisualTool(annotationNavigationTextSelectionTool);
        
                // open file from session folder and add images from file to the image viewer
                docViewer.openFile("VintasoftImagingDemo.pdf");
            </script>
        </body>
        </html>
        
    7. Run the ASP.NET WebForms application and see the result.