Reference Guide
DocuVieware Lite / ASP.NET Web Forms DocuVieware Lite integration
In This Topic
    ASP.NET Web Forms DocuVieware Lite integration
    In This Topic
     Overview

    This tutorial will show you how to integrate DocuVieware Lite™ in a newly created C# ASP.NET Web Forms project.

    DocuVieware Lite™ requires .NET Framework 4.6 or above.
     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 DocuViewareDemo which is new ASP.NET 4.6 Web Forms project.

    Depending on your Visual Studio version, you may not already have a Global.asax file in your project. In that case you want to add it too. This is also done through the Add > New item... menu, then select Global Application Class in the list.

    Here is the structure obtained:

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

     Adding mandatory referencies

    The references you need to add are:

    • GdPicture.NET.14.WEB.DocuVieware.dll found in [INSTALLATION FOLDER]\Redist\DocuVieware (.NET Framework 4.6)\
    • System.Web.Http from the Microsoft ASP.NET Web API

    You may not have the mandatory System.Web.Http namespace directly available on your system, this is because it requires Microsoft ASP.NET Web API to be installed first.

    To do this, simply run the following command 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

           

    You might also need to add Newtonsoft JSON, even though it should be already in the references but the version is outdated and it will most probably cause an error at runtime.

    To do this, still in the Package Manager Console (from the Tools menu, select NuGet Package Manager and then click Package Manager Console), run the following command:

    PM> Install-Package Newtonsoft.JSON

    The project references should look like this:

    At this point, please make sure that the GdPicture.NET.14.Web.DocuVieware reference is marked as Copy Local : True in its properties window: https://msdn.microsoft.com/library/t1zz5y8c(v=vs.100).aspx

    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.image.gdimgplug.dll (for a 32-bit execution)
    • GdPicture.NET.14.Imaging.Rendering.Skia.dll (for a 32-bit execution)
    • GdPicture.NET.14.jbig2.encoder.dll (for a 32-bit execution)
    • GdPicture.NET.14.filters.64.dll (for a 64-bit execution)
    • GdPicture.NET.14.image.gdimgplug.64.dll (for a 64-bit execution)
    • GdPicture.NET.14.Imaging.Rendering.Skia.64.dll (for a 64-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.

     Licensing and configuring

    You need to go into Global.asax.cs, add a mandatory import and handle the licensing part and the configuration part of DocuVieware Lite™ as well.

    You can find the sample source code available here: [INSTALLATION FOLDER]\Samples\ASP.NET\DocuVieware Lite\aspnet-webform_app\Global.asax.cs

     Here is the mandatory import you need to add.

    Importing the dll.
    Copy Code
    using GdPicture14.WEB;
    Importing the dll.
    Copy Code
    Imports GdPicture14.WEB

    To properly unlock DocuVieware Lite™ you are going to add a call to the RegisterKEY() method in the Application_Start event. Then please enter your license key in the method, you can ask your free DocuVieware Lite license key here: http://www.docuvieware.com/docuvieware-lite/

    Unlocking the DocuVieware Lite™.
    Copy Code
    DocuViewareLicensing.RegisterKEY("XXXX"); //Unlocking DocuVieware
    //You need to replace "XXXX" by your actual license key.
    Unlocking the DocuVieware Lite™.
    Copy Code
    DocuViewareLicensing.RegisterKEY("XXXX") 'Unlocking DocuVieware
    'You need to replace "XXXX" by your actual license key.

    To set up the configuration of the DocuVieware Lite™ you are going to add a call to the DocuViewareManager.SetupConfiguration() method in the Application_Start event. At this point 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.

    Configuring the DocuVieware Lite™.
    Copy Code
    DocuViewareManager.SetupConfiguration(true, DocuViewareSessionStateMode.InProc, HttpRuntime.AppDomainAppPath + "\\Cache");
    Configuring the DocuVieware Lite™.
    Copy Code
    DocuViewareManager.SetupConfiguration(True, DocuViewareSessionStateMode.InProc, HttpRuntime.AppDomainAppPath + "\\Cache")
    You can find the sample source code available here: [INSTALLATION FOLDER]\Samples\ASP.NET\DocuVieware Lite\aspnet-webform_app\Global.asax.cs
           
     DocuVieware integration

    Step 1 : Add the assembly registration to the page so you can add a DocuVieware Lite™ control on it. Here is the ASP.NET code you need to add to do this:

    Adding the assembly registration.
    Copy Code
    <%@ Register Assembly="GdPicture.NET.14.WEB.DocuVieware" Namespace="GdPicture14.WEB" TagPrefix="cc1" %>

    Step 2 : Add and set the DocuVieware1 object properties in the Default.aspx page, after some clean-up, like this:

    Defining the DocuVieware1 object.
    Copy Code
    <cc1:DocuVieware ID="DocuVieware1" runat="server" Height="800px" Width="1000px" />

    DocuVieware Lite™ will now have a fixed size of 1000x800 pixels.

    Here is how the page source code looks like in the end:

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

     Loading a document

    Loading a document into your newly created DocuVieware Lite™ page is easy, you simply need to load your document into a Stream object and call the LoadFromStream method from the DocuVieware class.

    Step 1: In the page code behind, create a stream and load your document in it.

    Loading a document.
    Copy Code
    FileStream stream = new FileStream(@"D:\input_document.pdf", FileMode.Open, FileAccess.Read);
    Loading a document.
    Copy Code
    Dim stream As New FileStream("D:\input_document.pdf", FileMode.Open, FileAccess.Read)

    Step 2: Call the LoadFromStream method in the Page_Load part so the document is displayed when the page is loaded.

    Loading a document content.
    Copy Code
    protected void Page_Load(object sender, EventArgs e)
     {
        if (!IsPostBack)
        {
           FileStream stream = new FileStream(@"D:\input_document.pdf", FileMode.Open, FileAccess.Read);
           DocuVieware1.LoadFromStream(stream, true, "input_document.pdf");
        }
     }
    Loading a document content.
    Copy Code
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
           Dim stream As New FileStream("D:\input_document.pdf", FileMode.Open, FileAccess.Read)
           DocuVieware1.LoadFromStream(stream, True, "input_document.pdf")
        End If
     End Sub