Reference Guide
Tutorials / ASP.NET MVC Razor / Your first DocuVieware MVC Razor page
In This Topic
    Your first DocuVieware MVC Razor page
    In This Topic
     Overview

    This tutorial will show you how to integrate DocuVieware™ in a newly created C# MVC 5 project with Razor view engine.

    DocuVieware™ requires .NET Framework 4.6 or above.
    The screenshots have been taken using Visual Studio 2015 and GdPicture.NET™ 14, it may differ from the current release.
     Empty project creation

    Start with the File > New > Project... menu, then choose Web > ASP.NET Web Application. In this tutorial you will be working on DocuViewareRazor which is new ASP.NET 4.6 MVC project.

    Here is the structure obtained:

    Now that the project structure is ready, the next step will be to add project references.

     Adding mandatory referencies
     Prerequisite references

    You need to add a couple of things to the project before adding DocuVieware™, you need Microsoft ASP.NET Web API and Newtonsoft JSON (even though this one should be already in the references but the version is outdated and it will most probably cause an error at runtime).

    To do this, simply run the following commands one after the other in the Package Manager Console (from the Tools menu, select NuGet Package Manager and then click Package Manager Console):

    PM> Install-Package Microsoft.AspNet.WebApi
    PM> Install-Package Newtonsoft.JSON

    Once the installation is done, the correct references have been automatically added to the project and, among others, you should see a System.Web.Http reference.

     DocuVieware references

    Step 1: The first reference to add is GdPicture.NET.14.WEB.DocuVieware.dll that is found in [INSTALLATION FOLDER]\Redist\DocuVieware\.

    Once added, make sure it is marked as Copy Local : True in its properties window: https://msdn.microsoft.com/library/t1zz5y8c(v=vs.100).aspx

    Step 2: You also need to add DocuVieware™ own JavaScript and CSS to the project, docuvieware-min.js and docuvieware-min.css, both found in [INSTALLATION FOLDER]\Redist\DocuVieware (Resources)\.

    You already have folders for such resources so just add docuvieware-min.js to the Scripts folder and docuvieware-min.css to the Content folder, like this:

    Step 3: Now you need to add them to the bundles so they are available to add them to the page later on, this is done in the BundleConfig.cs file that is in the App_Start folder of the project:

    Adding the DocuVieware resources.
    Copy Code
    // Adding the DocuVieware resources we need in a new bundle
    bundles.Add(new ScriptBundle("~/bundles/docuvieware").Include("~/Scripts/docuvieware-min.js"));
    bundles.Add(new StyleBundle("~/Content/docuvieware").Include("~/Content/docuvieware-min.css"));

    Once done, the source code looks like this:

    Step 4: You also need to take care of extra libraries that are mandatory for deployment, those files are found in [INSTALLATION FOLDER]\Redist\

    • GdPicture.NET.14.filters.dll (for a 32-bit execution)
    • GdPicture.NET.14.filters.64.dll (for a 64-bit execution)
    • GdPicture.NET.14.image.gdimgplug.dll (for a 32-bit execution)
    • GdPicture.NET.14.image.gdimgplug.64.dll (for a 64-bit execution)
    • GdPicture.NET.14.Imaging.Rendering.Skia.dll (for a 32-bit execution)
    • GdPicture.NET.14.Imaging.Rendering.Skia.64.dll (for a 64-bit execution)
    • GdPicture.NET.14.jbig2.encoder.dll (for a 32-bit execution)
    • GdPicture.NET.14.jbig2.encoder.64.dll (for a 64-bit execution)

    They need to be added to the project (using the Add > Existing item... menu) and once done, the "Build Action" property should be set to "Content" and the "Copy to Output Directory" property should set to "Copy always" for each file.

     Setting up licensing

    Now that the references are properly set, you need to go to the Global.asax.cs file of the project to add some mandatory imports and handle the DocuVieware™ licensing part as well.

    Importing the dll.
    Copy Code
    using GdPicture14.WEB;

    To properly unlock DocuVieware™ you are going to add a call to the RegisterKEY method in the Application_Start event.

    But first you need to setup the configuration, for that you need to create a new folder in the project that will be used for cache, for the sake of clarity simply name it Cache.

    Unlocking the DocuVieware™.
    Copy Code
    DocuViewareManager.SetupConfiguration(true, DocuViewareSessionStateMode.InProc, HttpRuntime.AppDomainAppPath + "\\Cache");
    DocuViewareLicensing.RegisterKEY("XXXX"); //Unlocking DocuVieware

    You need to replace "XXXX" by your actual license key.

    Here is what the Global.asax.cs file should look like at this point:

     DocuVieware integration

    You are going to integrate a DocuVieware™ instance in the index page, but of course the exact same applies to any other page or content.

    Step 1: Create a new folder in the project root called Cache that will be used later on to store session data when the service will be running.

    Step 2: Open the page that is located in Views > Home and it is called Index.cshtml. As it already have content in it, remove it all (except the title code) to start clean.

    Inject the JavaScript and CSS resources (that were added in a bundle earlier) in the page so you have them ready for the main control integration, this is done using this code:

    Integrating a DocuVieware™ instance.
    Copy Code
    @Styles.Render("~/Content/docuvieware")
    @Scripts.Render("~/bundles/docuvieware")
           

    Step 3: Create a div and insert the DocuVieware™ control in Index.cshtml.

    Using the object initializer, set the ID and finally Height and Width are set to 100% for the control to fit the div.

    Creating a div.
    Copy Code
    <div style="height: 1000px; margin-top: 15px;">
        @{
           GdPicture14.WEB.DocuVieware docuVieware = new GdPicture14.WEB.DocuVieware
           {
              ID = "DocuVieware1",
              Height = new System.Web.UI.WebControls.Unit("100%"),
              Width = new System.Web.UI.WebControls.Unit("100%")
           };
           docuVieware.RenderControl(Output);
           docuVieware.Dispose();
        }
     </div>

    Here is what the Index.cshtml finally looks like after the integration is complete:

    That’s it! You can start the project and load documents in your brand new DocuVieware™.