Setup Doconut in .NET Standard / Core

Startup.cs file

Within the Startup.cs file of a .NET Core project, these lines of code define a middleware pipeline configuration using the MapWhen method.

The provided predicate checks if the incoming request path ends with "DocImage.axd". Inside this block, the UseDoconut method is called with a DoconutOptions object as an argument.

app.MapWhen(
  context => context.Request.Path.ToString().EndsWith("DocImage.axd"),
  appBranch =>
  {
      appBranch.UseDoconut(new DoconutOptions { UnSafeMode = false, ShowDoconutInfo = false });
  }

Add Doconut Namespaces

In your project, add the following usings:

using Doconut;
using Doconut.Configs;
using Doconut.Formats;
using Doconut.Clouds;

Instantiate Viewer object

This line instantiates a new instance of the Viewer class, allowing you to create a viewer object within your code.

var docViewer = new Viewer(_cache, _accessor, licenseFilePath);

Setup a DocOptions object

Per example, this line initializes a new PdfConfig object named "config" with specific configurations for handling PDF documents.

var documentOptions = new DocOptions
{
Password = "",
ImageResolution = 200,
TimeOut = 30
};

Setup a config object

Per example, this line initializes a new PdfConfig object named "config" with specific configurations for handling PDF documents.

var config = new PdfConfig { DefaultRender = true, ExtractHyperlinks = true };

Open your document

This line invokes the "OpenDocument" method of the viewer object, passing the path of the document file located on the server and the previously configured PdfConfig and DocOptions objects as parameters.

var token = docViewer.OpenDocument(pathToFile, config, documentOptions);

Add the viewer in your HTML

<div id="div_ctlDoc"></div>

Add the following CSS And javascript files in the page. These scripts are included in the ZIP file with code samples.

<link rel="stylesheet" href="css/viewer.css" />
<!-- Main Viewer Related Scripts -->
<script src="scripts/jquery.min.js"></script>
<script src="scripts/docViewer.js"></script>
<script src="scripts/splitter.js"></script>
<script src="scripts/search.js"></script>
<script src="scripts/documentLinks.js"></script>

<!-- Viewer functions -->
<script src="scripts/docViewer.UI.js?v=1"></script>

Add Licenses to Your Project

Automatic License Detection

Doconut can automatically detect licenses if they are placed within the project's wwwroot folder.

To initialize the docViewer with automatic license detection, use the following line:

var docViewer = new Viewer(_cache, _accessor);

Add Manual Default License

You can manually specify the path to a single default license file when initializing the viewer.

var licenseFilePath = Path.Combine(_hostingEnvironment.WebRootPath, "path/to/your/license");
var docViewer = new Viewer(_cache, _accessor, licenseFilePath);

Add License by Stream

This method uses the Viewer.DoconutLicense(Stream licenseStream) overload to add a license using a stream.

using (var licenseStream = new FileStream("path/to/your/license", FileMode.Open))
{
Viewer.DoconutLicense(licenseStream);
}

Add License by XML Document

This method uses the Viewer.DoconutLicense(XMLDocument licence) overload to add a license using an XML document.

var xmlDoc = new XmlDocument();
xmlDoc.Load("path/to/your/license.xml");
Viewer.DoconutLicense(xmlDoc);

Manual Default Multiple Plugin Licenses

If you need to specify multiple licenses, you can provide a list of file paths to the viewer initialization.

List<string> licenseFilePaths = new List<string>
{
    Path.Combine(_hostingEnvironment.WebRootPath, "Doconut.Viewer.lic"),
    Path.Combine(_hostingEnvironment.WebRootPath, "Doconut.Viewer.Annotation.lic"),
    Path.Combine(_hostingEnvironment.WebRootPath, "Doconut.Viewer.Search.lic")
};
var docViewer = new Viewer(_cache, _accessor, licenseFilePaths);

Add Plugin License by Stream

This method uses the Viewer.SetLicensePlugin(Stream pluginLicence) overload to add a plugin license using a stream.

using (var pluginLicenseStream = new FileStream("path/to/your/plugin-license.lic", FileMode.Open))
{
Viewer.SetLicensePlugin(pluginLicenseStream);
}

Add Plugin License by XML Document

This method uses the Viewer.SetLicensePlugin(XMLDocument xmlPluginLicence) overload to add a plugin license using an XML document.

var pluginXmlDoc = new XmlDocument();
pluginXmlDoc.Load("path/to/your/plugin-license.xml");
Viewer.SetLicensePlugin(pluginXmlDoc);


Required NuGet Packages

To ensure your project is fully compatible with .NET Core Standard, the following NuGet packages need to be included, listed in alphabetical order. These packages provide the necessary libraries and tools required for the application's functionality:

  • MessagePack - Version 2.5.140
  • Microsoft.Bcl.AsyncInterfaces - Version 8.0.0
  • Microsoft.Extensions.Caching.Abstractions - Version 8.0.0
  • Microsoft.Extensions.Configuration - Version 8.0.0
  • Microsoft.Extensions.Configuration.Abstractions - Version 8.0.0
  • Microsoft.Extensions.Configuration.FileExtensions - Version 8.0.0
  • Microsoft.Extensions.Configuration.Json - Version 8.0.0
  • Microsoft.Extensions.FileProviders.Abstractions - Version 8.0.0
  • Microsoft.Extensions.FileProviders.Physical - Version 8.0.0
  • Microsoft.Extensions.FileSystemGlobbing - Version 8.0.0
  • Microsoft.Extensions.Primitives - Version 8.0.0
  • System.Buffers - Version 4.5.1
  • System.Formats.Asn1 - Version 8.0.0
  • System.Numerics.Vectors - Version 4.5.0
  • System.Security.Cryptography.Cng - Version 5.0.0
  • System.Security.Cryptography.Pkcs - Version 8.0.0
  • System.Text.Encoding.CodePages - Version 8.0.0
  • System.Text.Encodings.Web - Version 8.0.0
  • System.Text.Json - Version 8.0.3
  • System.Threading.Tasks.Extensions - Version 4.5.4


Render Configuration Options

You can configure the rendering behavior using the following options:

  • CadConfig: Used for DWG, DXF, and DGN files.
  • EmailConfig: Used for EML, EMLX, and MSG files.
  • EpubConfig: Used for EPUB files.
  • ExcelConfig: Used for Excel and CSV files.
  • MhtConfig: Used for MHT files.
  • PptConfig: Used for PowerPoint files.
  • ProjectConfig: Used for MPP files.
  • PsdConfig: Used for PSD files.
  • TxtConfig: Used for TXT files.
  • TiffConfig: Used for TIFF files.

The render options are configured using the DefaultRender property:

  • DefaultRender = true : This option offers higher quality rendering but uses more server memory and processing time.
  • DefaultRender = false : This option provides faster rendering at the expense of slightly reduced quality. It optimizes processing time and memory usage.

Example usage:

var config = new CadConfig { DefaultRender = false }; // or true

Download Required CSS and JS Files

To ensure Doconut functions properly, you need to include specific CSS and JS files in your project. You can download a ZIP file containing all the necessary files using the link below: