Click or drag to resize

Using DocumentUltimate in an ASP.NET Core project

To use DocumentUltimate in an "ASP.NET Core on .NET Framework" Project, do the following in Visual Studio:

  1. Make sure you have added references to DocumentUltimate assemblies as described here.

  2. Make sure you have the following packages with these minimum versions in your project (update them in Nuget Package Manager if necessary):

    • Microsoft.AspNetCore 2.0.2
    • Microsoft.AspNetCore.Mvc 2.0.3
    • Microsoft.AspNetCore.Session 2.0.2

    Minimum supported version is ASP.NET Core MVC 2.0.3 on .NET Framework 4.6.1 (this is because 2.0.3 fixes a bug related to referencing external DLLs in a razor page).

  3. Open Startup.cs of your project.

    Add GleamTech to the ASP.NET Core services container. Insert the marked line into the ConfigureServices method of your Startup.cs:

    C#
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    
    
        //Add GleamTech to the ASP.NET Core services container.
        //----------------------
        services.AddGleamTech();
        //----------------------
    }

    Register GleamTech to the ASP.NET Core HTTP request pipeline. Insert the marked line into the Configure method of your Startup.cs:

    C#
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }
    
    
        //Register GleamTech to the ASP.NET Core HTTP request pipeline.
        //----------------------
        app.UseGleamTech();
        //----------------------
    
    
        app.UseStaticFiles();
    
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

    Note that order of app.UseXXX methods is important so app.UseGleamTech should be placed before app.UseStaticFiles and app.UseMvc.

  4. Set DocumentUltimate's global configuration. For example, you may want to set the license key and the document cache location. Insert some of the following lines (if overriding a default value is required) after app.UseGleamTech call into the ConfigureServices method of your Startup.cs:

    C#
    //Set this property only if you have a valid license key, otherwise do not
    //set it so DocumentUltimate runs in trial mode.
    DocumentUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34...";
    
    //The default CacheLocation value is "~/App_Data/DocumentCache"
    //Both virtual and physical paths are allowed (or a Location instance for one of the supported 
    //file systems like Amazon S3 and Azure Blob).
    DocumentUltimateWebConfiguration.Current.CacheLocation = "~/App_Data/DocumentCache";
    Tip Tip

    Alternatively you can specify the configuration in appsettings.json file.

    JavaScript
    {
      "DocumentUltimate:LicenseKey": "QQJDJLJP34...",
      "DocumentUltimateWeb:CacheLocation": "~/App_Data/DocumentCache"
    }
    

    As you would notice, DocumentUltimate: prefix maps to DocumentUltimateConfiguration.Current and DocumentUltimateWeb: prefix maps to DocumentUltimateWebConfiguration.Current.

  5. Create a new View (eg. Index.cshtml) and insert these lines:

    C#
    @using GleamTech.AspNet.Core
    @using GleamTech.DocumentUltimate
    @using GleamTech.DocumentUltimate.AspNet
    @using GleamTech.DocumentUltimate.AspNet.UI
    
    <!DOCTYPE html>
    @{
        var documentViewer = new DocumentViewer
        {
            Width = 800,
            Height = 600,
            Document = "~/Documents/Document.docx"
        };
    }
    <html>
        <head>
            <title>Document Viewer</title>
            @this.RenderHead(documentViewer)
        </head>
        <body>
            @this.RenderBody(documentViewer)
        </body>
    </html>

    This will render a DocumentViewer control in the page which loads and displays the source document ~/Documents/Document.docx. Upon first view, internally DocumentViewer will convert the source document to PDF (used for "Download as Pdf" and also for next conversion step) and then to XPZ (a special web-friendly format which DocumentViewer uses to actually render documents in the browser). So in this case the user will see "please wait awhile..." message in the viewer for a few seconds. These generated PDF and XPZ files will be cached and upon consecutive page views, the document will be served directly from the cache so the user will see the document instantly on second viewing. When you modify the source document, the cached files are invalidated so your original document and the corresponding cached files are always synced automatically. Note that it's also possible to pre-cache documents via DocumentCache.PreCacheDocument method (e.g. when your user uploads a document), see Pre-caching documents for more information.

    Tip Tip

    Alternatively you can add the namespaces globally in Views/_ViewImports.cshtml to avoid adding namespaces in your pages every time.