VintaSoft Imaging .NET SDK 14.0: Documentation for Web developer
In This Topic
    Add web PDF document editor to an ASP.NET MVC5 application
    In This Topic
    This tutorial shows how to create a blank ASP.NET Web application in Visual Studio .NET 2019 and add PDF document editor to ASP.NET MVC5 application.

    Here are steps, which must be done:
    1. Create a blank ASP.NET MVC5 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 MVC and Web API:

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

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



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

      ASP.NET MVC5 application should use System.Drawing library as drawing engine because ASP.NET MVC5 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 "Global.asax.cs" file, add code line "Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();" at the beginning of Application_Start 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, work with PDF document.

      • Create web service that allows to upload/download file

        • Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
        • Select "Empty API controller" template, set the controller name to the "MyVintasoftFileApiController" and press the "Add" button
        • Specify that MyVintasoftFileApiController class is derived from Vintasoft.Imaging.Web.Api2Controllers.VintasoftFileApi2Controller class

          Here are source codes of MyVintasoftFileApiController class:
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftFileApiController : Vintasoft.Imaging.Web.Api2Controllers.VintasoftFileApi2Controller
              {
          
                  public MyVintasoftFileApiController()
                      : base()
                  {
                  }
          
              }
          }
          
          

      • Create web service that allows to manage image collection

        • Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
        • Select "Empty API controller" template, set the controller name to the "MyVintasoftImageCollectionApiController" and press the "Add" button
        • Specify that MyVintasoftImageCollectionApiController class is derived from Vintasoft.Imaging.Web.Api2Controllers.VintasoftImageCollectionApi2Controller class

          Here are source codes of MyVintasoftImageCollectionApiController class:
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftImageCollectionApiController :
                  Vintasoft.Imaging.Web.Api2Controllers.VintasoftImageCollectionApi2Controller
              {
          
                  public MyVintasoftImageCollectionApiController()
                      : base()
                  {
                  }
          
              }
          }
          
          

      • 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 "Controllers" folder and select the "Add => Controller..." menu from context menu
        • Select "Empty API controller" template, set the controller name to the "MyVintasoftImageApiController" and press the "Add" button
        • Specify that MyVintasoftImageApiController class is derived from Vintasoft.Imaging.Web.Api2Controllers.VintasoftImageApi2Controller class

          Here are source codes of MyVintasoftImageApiController class:
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftImageApiController : Vintasoft.Imaging.Web.Api2Controllers.VintasoftImageApi2Controller
              {
          
                  public MyVintasoftImageApiController()
                      : base()
                  {
                  }
          
              }
          }
          
          

      • Create web service that allows to work with PDF document

        • Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
        • Select "Empty API controller" template, set the controller name to the "MyVintasoftPdfApiController" and press the "Add" button
        • Specify that MyVintasoftPdfApiController class is derived from Vintasoft.Imaging.Pdf.Web.Api2Controllers.VintasoftPdfApi2Controller class

          Here are source codes of MyVintasoftPdfApiController class:
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftPdfApiController :
                  Vintasoft.Imaging.Pdf.Web.Api2Controllers.VintasoftPdfApi2Controller
              {
          
                  public MyVintasoftPdfApiController()
                      : base()
                  {
                  }
          
              }
          }
          

      • Open "App_Start\WebApiConfig.cs" file and check that ASP.NET MVC application correctly registers route for Web API controller.

        Here are C# source codes of WebApiConfig.cs file:
        using System.Web.Http;
        
        namespace WebApplication1
        {
            public static class WebApiConfig
            {
                public static void Register(HttpConfiguration config)
                {
                    config.Routes.MapHttpRoute(
                        name: "DemoAPI",
                        routeTemplate: "vintasoft/api/{controller}/{action}"
                    );
                }
            }
        }
        
        
    5. Server side: Create ASP.NET MVC 5 controller for web view that will display PDF document editor.

      • Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu


      • Select "MVC 5 Controller - Empty" template, set the controller name to the "DefaultController" and press the "Add" button


      • Open "App_Start\RouteConfig.cs" file and check that ASP.NET MVC application correctly registers route for MVC controller.

        Here are C# source codes of RouteConfig.cs file:
        using System.Web.Mvc;
        using System.Web.Routing;
        
        namespace WebApplication1
        {
            public class RouteConfig
            {
                public static void RegisterRoutes(RouteCollection routes)
                {
                    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        
                    routes.MapRoute(
                        name: "Default",
                        url: "{controller}/{action}",
                        defaults: new { controller = "Default", action = "Index" }
                    );
                }
            }
        }
        
        
        
    6. Server side: Check global configuration of ASP.NET MVC5 application.

      Open "Global.asax.cs" file and check that "Application_Start" method registers all areas in ASP.NET MVC application, configures global HTTP configuration for ASP.NET application, registers routes for ASP.NET MVC application.

      Here are C# source codes of Global.asax.cs file:
      using System;
      using System.Web;
      using System.Web.Mvc;
      using System.Web.Routing;
      using System.Web.Http;
      
      namespace WebApplication1
      {
          public class Global : HttpApplication
          {
              void Application_Start(object sender, EventArgs e)
              {
                  // Code that runs on application startup
                  AreaRegistration.RegisterAllAreas();
                  GlobalConfiguration.Configure(WebApiConfig.Register);
                  RouteConfig.RegisterRoutes(RouteTable.Routes);
              }
          }
      }
      
    7. Client side: Create web view for displaying PDF document editor.

      • Open "DefaultController.cs" file, press the right mouse button on the "Index" method of DefaultController class and select the "Add View..." menu from context menu
      • Select "MVC 5 View" template, click "Add" button, set view name to "Index", uncheck "Use a layout page" checkbox and press the "Add" button => "Views\Default\Index.cshtml" file will be created
    8. Client side: Add JavaScript libraries to the project.

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

      • Copy Vintasoft.Shared.js, Vintasoft.Imaging.js, Vintasoft.Imaging.Pdf.js, Vintasoft.Imaging.css and Vintasoft.Imaging.Pdf.css 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 PDF document editor
        • If web PDF document editor 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.Pdf.Dialogs.jQueryUI.js files from "<InstallPath>\VintaSoft Imaging .NET 14.0\Bin\JavaScript\" folder into "Scripts\" folder.

        • If web PDF document editor should use custom "standard" dialogs, please read how to create custom "standard" dialogs here.
    9. Client side: Add JavaScript code that allows to view, print, redact, verify, convert, save PDF document.

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

      • Open web view - file "Views\Default\Index.cshtml".


      • Add references to Vintasoft 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.Pdf.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.Pdf.js" type="text/javascript"></script>
        <script src="~/Scripts/Vintasoft.Imaging.Pdf.Dialogs.jQueryUI.js" type="text/javascript"></script>
        


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

        Here is HTML markup code:
        <h1 style="text-align: center">VintaSoft PDF Document Editor Demo (ASP.NET MVC5)</h1>
        
        <div id="pdfDocumentEditorContainer" style="height: 800px"></div>
        


      • Add JavaScript code that initializes and creates PDF document editor:

        Here is JavaScript code that initializes and creates PDF document editor:
        
        @{
            Layout = null;
        }
        
        <!DOCTYPE html>
        
        <html>
        <head>
            <meta name="viewport" content="width=device-width" />
            <title>VintaSoft PDF Document Editor Demo (ASP.NET MVC)</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.Pdf.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.Pdf.js" type="text/javascript"></script>
            <script src="~/Scripts/Vintasoft.Imaging.Pdf.Dialogs.jQueryUI.js" type="text/javascript"></script>
        </head>
        <body>
            <h1 style="text-align: center">VintaSoft PDF Document Editor Demo (ASP.NET MVC5)</h1>
        
            <div id="pdfDocumentEditorContainer" style="height: 800px"></div>
        
            <script type="text/javascript">
                // set the session identifier
                Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
                // specify web services, which should be used by Vintasoft Web PDF Document Editor
                Vintasoft.Shared.WebServiceJS.defaultFileService =
                    new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftFileApi");
                Vintasoft.Shared.WebServiceJS.defaultImageCollectionService =
                    new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftImageCollectionApi");
                Vintasoft.Shared.WebServiceJS.defaultImageService =
                    new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftImageApi");
                Vintasoft.Shared.WebServiceJS.defaultPdfService =
                    new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftPdfApi");
        
                // create settings for PDF document editor
                var pdfDocumentEditorSettings =
                    new Vintasoft.Imaging.Pdf.UI.WebPdfDocumentEditorControlSettingsJS("pdfDocumentEditorContainer");
        
                // create the PDF document editor
                var pdfDocumentEditor = new Vintasoft.Imaging.Pdf.UI.WebPdfDocumentEditorControlJS(pdfDocumentEditorSettings);
        
                // open file from session folder and add images from file to the image viewer
                pdfDocumentEditor.openFile("VintasoftImagingDemo.pdf");
            </script>
        </body>
        </html>
        
        
    10. Run the ASP.NET MVC5 application and see the result.