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

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

      Open Visual Studio .NET 2022 and create a new project, of ASP.NET Core Web application type:

      Configure the project to use .NET 8.0:

    2. Server side: Add references to the Vintasoft assemblies to your ASP.NET Core Web application.

      Copy 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.AspNetCore.ApiControllers.dll and Vintasoft.Imaging.Pdf.AspNetCore.ApiControllers.dll assemblies from "<SdkInstallPath>\VintaSoft Imaging .NET 14.0\Bin\DotNet8\AnyCPU\" directory to the "Bin" directory of ASP.NET Core Web application and add references to assemblies in ASP.NET Core Web application.



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

      If ASP.NET application must be used in Windows or Linux, SkiaSharp drawing engine should be used.
      If ASP.NET application must be used in Windows only, System.Drawing or SkiaSharp drawing engine should be used.

      Here are steps, which should be made for using SkiaSharp engine:
      • Add reference to the Vintasoft.Imaging.Drawing.SkiaSharp.dll assembly.
      • Add reference to the SkiaSharp nuget-package version 2.88.9.
      • Open "Startup.cs" file, add code line "Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();" at the beginning of ConfigureServices method - added code specifies that VintaSoft Imaging .NET SDK should use SkiaSharp library for drawing of 2D graphics.

      Here are steps, which should be made for using System.Drawing engine:
      • Add reference to the Vintasoft.Imaging.Gdi.dll assembly.
      • Open "Startup.cs" file, add code line "Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();" at the beginning of ConfigureServices 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.

      • Add the "Controllers" folder to the project.
      • 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 "API Controller - Empty" template, press the "Add" button, set the controller name to the "MyVintasoftFileApiController" and press the "Add" button
        • Specify that MyVintasoftFileApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileApiController class

          Here are source codes of MyVintasoftFileApiController class:
          using Microsoft.AspNetCore.Hosting;
          
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftFileApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileApiController
              {
          
                  public MyVintasoftFileApiController(IWebHostEnvironment hostingEnvironment)
                      : base(hostingEnvironment)
                  {
                  }
          
              }
          }
          
          
      • 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 "API Controller - Empty" template, press the "Add" button, set the controller name to the "MyVintasoftImageCollectionApiController" and press the "Add" button
        • Specify that MyVintasoftImageCollectionApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageCollectionApiController class

          Here are source codes of MyVintasoftImageCollectionApiController class:
          using Microsoft.AspNetCore.Hosting;
          
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftImageCollectionApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageCollectionApiController
              {
          
                  public MyVintasoftImageCollectionApiController(IWebHostEnvironment hostingEnvironment)
                      : base(hostingEnvironment)
                  {
                  }
          
              }
          }
          
          
      • 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 "API Controller - Empty" template, press the "Add" button, set the controller name to the "MyVintasoftImageApiController" and press the "Add" button
        • Specify that MyVintasoftImageApiController class is derived from Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageApiController class

          Here are source codes of MyVintasoftImageApiController class:
          using Microsoft.AspNetCore.Hosting;
          
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftImageApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftImageApiController
              {
          
                  public MyVintasoftImageApiController(IWebHostEnvironment hostingEnvironment)
                      : base(hostingEnvironment)
                  {
                  }
          
              }
          }
          
          
      • 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 "API Controller - Empty" template, press the "Add" button, set the controller name to the "MyVintasoftPdfApiController" and press the "Add" button
        • Specify that MyVintasoftPdfApiController class is derived from Vintasoft.Imaging.Pdf.AspNetCore.ApiControllers.VintasoftPdfApiController class

          Here are source codes of MyVintasoftPdfApiController class:
          using Microsoft.AspNetCore.Hosting;
          
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftPdfApiController :
                  Vintasoft.Imaging.Pdf.AspNetCore.ApiControllers.VintasoftPdfApiController
              {
          
                  public MyVintasoftPdfApiController(IWebHostEnvironment hostingEnvironment)
                      : base(hostingEnvironment)
                  {
                  }
              }
          }
          
    5. Server side: Create MVC 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 Controller - Empty" template, press the "Add" button, set the controller name to the "DefaultController" and press the "Add" button
      • Open "Startup.cs" file, add controllers with views to the services of ASP.NET Core application:


        Add created MVC controller to the endpoints of ASP.NET Core application:


        Enable static file serving for the current request path of ASP.NET Core application:


        Here are C# source codes of Startup.cs file:
        using Microsoft.AspNetCore.Builder;
        using Microsoft.AspNetCore.Hosting;
        using Microsoft.Extensions.Configuration;
        using Microsoft.Extensions.DependencyInjection;
        using Microsoft.Extensions.Hosting;
        
        namespace WebApplication1
        {
            public class Startup
            {
                public Startup(IConfiguration configuration)
                {
                    Configuration = configuration;
                }
        
                public IConfiguration Configuration { get; }
        
                // This method gets called by the runtime. Use this method to add services to the container.
                public void ConfigureServices(IServiceCollection services)
                {
                    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp library for drawing of 2D graphics
                    Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
        
                    // add Newtonsoft JSON for deserialization of JSON annotations
                    services.AddControllersWithViews().AddNewtonsoftJson();
        
                    services.AddRazorPages();
                }
        
                // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
                public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
                {
                    if (env.IsDevelopment())
                    {
                        app.UseDeveloperExceptionPage();
                    }
                    else
                    {
                        app.UseExceptionHandler("/Error");
                        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                        app.UseHsts();
                    }
        
                    app.UseHttpsRedirection();
                    app.UseStaticFiles();
        
                    app.UseRouting();
        
                    app.UseAuthorization();
        
                    app.UseEndpoints(endpoints =>
                    {
                        endpoints.MapControllerRoute("default", "{controller=Default}/{action=Index}/{id?}");
                    });
                }
            }
        }
        
        
    6. 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 "Razor View - Empty" template, click "Add" button, set view name to "Index" and press the "Add" button => "Views\Default\Index.cshtml" file will be created
    7. Client side: Add JavaScript libraries to the project.

      • Add the "wwwroot\js\" folder to ASP.NET Core 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 "wwwroot\js\" 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" Bootstrap dialogs:
          • Add Bootstrap and jQuery libraries to the project.
          • Copy Vintasoft.Imaging.Dialogs.Bootstrap.js and Vintasoft.Imaging.Pdf.Dialogs.Bootstrap.js files from "<InstallPath>\VintaSoft Imaging .NET 14.0\Bin\JavaScript\" folder into "wwwroot\js\" folder.
        • If web PDF document editor should use ready-to-use "standard" jQuery UI dialogs:
          • Add jQuery and jQuery UI libraries to the project.
          • 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 "wwwroot\js\" folder.
        • If web PDF document editor should use custom "standard" dialogs, please read how to create custom "standard" dialogs here.

    8. Client side: Add JavaScript code that allows to view, print, redact, verify, convert, save PDF document.

      • Create folder "wwwroot\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 used JavaScript libraries:
        • If Bootstrap dialogs are used, add references to the Bootstrap files and Vintasoft JavaScript files.
          Here is HTML code that adds references to the Bootstrap and Vintasoft JavaScript files:
          <link rel="stylesheet" type="text/css" href="~/lib/bootstrap/dist/css/bootstrap.min.css">
          <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.css">
          <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.Pdf.css">
          
          <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
          
          <script src="~/js/Vintasoft.Shared.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.Dialogs.Bootstrap.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.Pdf.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.Pdf.Dialogs.Bootstrap.js" type="text/javascript"></script>
          

        • If jQuery UI dialogs are used, add references to the jQuery files and Vintasoft JavaScript files.
          Here is HTML code that adds references to the jQuery and Vintasoft JavaScript files:
          <link rel="stylesheet" type="text/css" href="~/js/jquery-ui-css/jquery-ui.min.css">
          <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.css">
          <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.Pdf.css">
          
          <script src="~/js/jquery-3.3.1.min.js" type="text/javascript"></script>
          <script src="~/js/jquery-ui.min.js" type="text/javascript"></script>
          
          <script src="~/js/Vintasoft.Shared.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.Dialogs.jQueryUI.js" type="text/javascript"></script>
          <script src="~/js/Vintasoft.Imaging.Pdf.js" type="text/javascript"></script>
          <script src="~/js/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 Core)</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 displays PDF document editor:
        @{
        }
        
        <html>
        <head>
            <meta name="viewport" content="width=device-width" />
            <title>VintaSoft PDF Document Editor Demo (ASP.NET Core)</title>
        
            <link rel="stylesheet" type="text/css" href="~/lib/bootstrap/dist/css/bootstrap.min.css">
            <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.css">
            <link rel="stylesheet" type="text/css" href="~/js/Vintasoft.Imaging.Pdf.css">
        
            <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
        
            <script src="~/js/Vintasoft.Shared.js" type="text/javascript"></script>
            <script src="~/js/Vintasoft.Imaging.js" type="text/javascript"></script>
            <script src="~/js/Vintasoft.Imaging.Dialogs.Bootstrap.js" type="text/javascript"></script>
            <script src="~/js/Vintasoft.Imaging.Pdf.js" type="text/javascript"></script>
            <script src="~/js/Vintasoft.Imaging.Pdf.Dialogs.Bootstrap.js" type="text/javascript"></script>
        </head>
        
        <body>
            <h1 style="text-align: center">VintaSoft PDF Document Editor Demo (ASP.NET Core)</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>
        
    9. Run the ASP.NET Core Web application and see the result.