Setup Doconut in .NET 6

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 javascript files in the page. These scripts are included in the ZIP file with code samples.

<!-- Main Viewer Related Scripts -->
<script src="scripts/splitter.js"></script>
<script src="scripts/docViewer.js"></script>
<script src="scripts/documentLinks.js"></script>

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