.NET Standard / Core のセットアップ

Startup.cs ファイル

.NET Core プロジェクトの Startup.cs ファイル内で、これらのコード行は MapWhen メソッドを使用したミドルウェア パイプライン構成を定義します。 提供された述語は、受信リクエストのパスが DocImage.axd で終わるかどうかをチェックします。このブロック内では、UseDoconut メソッドが DoconutOptions オブジェクトを引数として呼び出されます。

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

Doconut 名前空間を追加

プロジェクトに、次の using ステートメントを追加します:

Usings
using Doconut;
using Doconut.Configs;
using Doconut.Clouds;

// TODO: implement licence loading, viewer registration, document opening, conversion using current API

Viewer オブジェクトをインスタンス化

この行は Viewer クラスの新しいインスタンスを生成し、コード内で viewer オブジェクトを作成できるようにします。

Instantiation
// Viewer is injected; no explicit construction required in Doconut.NETStandard 26.9.0

DocOptions オブジェクトを設定

特定の構成を持つ DocOptions オブジェクトの初期化例:

DocOptions
var documentOptions = new DocOptions
{
    Password = "",
    // ImageResolution is obsolete; omitted.
    TimeOut = 30
};

設定オブジェクトを設定

PDF ドキュメントを処理するための特定の構成で新しい PdfConfig オブジェクトを初期化します:

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

ドキュメントを開く

この行は viewer オブジェクトの OpenDocument メソッドを呼び出し、サーバー上にあるドキュメントファイルのパスと、事前に設定された PdfConfig および DocOptions オブジェクトをパラメータとして渡します。

OpenDocument
dynamic viewer = null;
var token = viewer.LoadDocument(path, null, null);

HTML に viewer を追加

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

CSS と JavaScript ファイルを追加

ページに次の CSS と JavaScript ファイルを追加します。これらのスクリプトはコードサンプルが含まれた ZIP ファイルに含まれています。

HTML Headers
<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>

プロジェクトにライセンスを追加

自動ライセンス検出

自動ライセンス検出で docViewer を初期化するには、次の行を使用します:

C#
```csharp
// Create a Viewer instance using the current API (no constructor arguments required).
var docViewer = new Viewer();
```

手動デフォルトライセンスを追加

viewer を初期化する際に、単一のデフォルトライセンスファイルへのパスを手動で指定できます。

C#
using System.IO;
using Microsoft.Extensions.DependencyInjection;
using Doconut;

var licenseFilePath = Path.Combine(builder.Environment.WebRootPath, "path/to/your/license");
var docViewer = app.Services.GetRequiredService<Viewer>();

ストリームでライセンスを追加

このメソッドは Viewer.DoconutLicense(Stream licenseStream) のオーバーロードを使用して、ストリームでライセンスを追加します。

C#
using System.IO;
using Doconut.Infrastructure.Licensing;

using (var licenseStream = new FileStream("path/to/your/license", FileMode.Open, FileAccess.Read))
{
    var license = new DoconutLicense { DocBytes = new BinaryReader(licenseStream).ReadBytes((int)licenseStream.Length) };
}

XML ドキュメントでライセンスを追加

このメソッドは Viewer.DoconutLicense(XMLDocument licence) のオーバーロードを使用して、XML ドキュメントでライセンスを追加します。

C#
using System.Xml;
using Doconut.Infrastructure.Licensing;

var xmlDoc = new XmlDocument(); // load the license XML
xmlDoc.Load("path/to/your/license.xml");
var license = new DoconutLicense(); // instantiate license object (populate properties as needed)

手動デフォルト複数プラグインライセンス

複数のライセンスを指定する必要がある場合、viewer の初期化時にファイルパスのリストを提供できます。

C#
```csharp
// Prepare the paths to the viewer licence files (kept for reference; the current API loads them automatically)
var 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")
};

// The Viewer class no longer requires the licences in its constructor.
// Create an instance with the default constructor.
var docViewer = new Viewer();

// Open a document (e.g., a PDF) and obtain a token that represents the opened file.
string token = await docViewer.OpenDocumentAsync(
    filePath: Path.Combine(_hostingEnvironment.WebRootPath, "sample.pdf"),
    options: new DocOptions(),
    ct: CancellationToken.None);
```

ストリームでプラグインライセンスを追加

このメソッドは Viewer.SetLicensePlugin(Stream pluginLicence) のオーバーロードを使用して、ストリームでプラグインライセンスを追加します。

C#
using (var pluginLicenseStream = new FileStream("path/to/your/plugin-license.lic", FileMode.Open))
{
    // In Doconut.NETStandard 26.9.0 the license is supplied via the configuration
    // passed to OpenDocumentAsync (BaseConfig), so the explicit SetLicensePlugin call
    // is no longer required. Keep the license file accessible to the viewer or
    // include it in your BaseConfig as shown in other samples.
}

XML ドキュメントでプラグインライセンスを追加

このメソッドは Viewer.SetLicensePlugin(XMLDocument xmlPluginLicence) のオーバーロードを使用して、XML ドキュメントでプラグインライセンスを追加します。

C#
// The license XML is discovered automatically by the viewer in Doconut.NETStandard 26.9.0.
// No explicit API call is required to register it.

string token = await Viewer.OpenDocumentAsync(
    "path/to/your/document.pdf",
    null, // DocOptions – use default settings
    CancellationToken.None);

必要な NuGet パッケージ

.NET Core Standard と完全に互換性を持たせるために、以下の NuGet パッケージをアルファベット順で含める必要があります。

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

レンダー構成オプション

以下のオプションを使用してレンダリング動作を構成できます:

  • CadConfig: DWG、DXF、DGN ファイルに使用されます。
  • EmailConfig: EML、EMLX、MSG ファイルに使用されます。
  • EpubConfig: EPUB ファイルに使用されます。
  • ExcelConfig: Excel と CSV ファイルに使用されます。
  • MhtConfig: MHT ファイルに使用されます。
  • PptConfig: PowerPoint ファイルに使用されます。
  • ProjectConfig: MPP ファイルに使用されます。
  • PsdConfig: PSD ファイルに使用されます。
  • TxtConfig: TXT ファイルに使用されます。
  • TiffConfig: TIFF ファイルに使用されます。

レンダーオプション構成

レンダーオプションは DefaultRender プロパティを使用して構成されます:

  • DefaultRender = true : このオプションは高品質なレンダリングを提供しますが、サーバーメモリと処理時間を多く使用します。
  • DefaultRender = false : このオプションは若干品質が低下する代わりに、より高速なレンダリングを提供します。

画像アノテーションの追加方法

C# で

1. ドキュメントを開き、最初のページのサイズを取得します。 2. ページサイズで AnnotationManager を初期化します。 3. ImageAnnotation を作成し、imgUrl に画像パスを設定し、Rectangle 内で位置とサイズを指定します。 4. アノテーションをマネージャに追加し、ドキュメントビューアでロードして表示します。

C#
using Doconut.Annotations;
using System.Drawing;

// Placeholder: open the document and obtain page dimensions using the current Doconut.NETStandard API.
// Placeholder: create an annotation manager for the page size.

string imgUrl = "img/sample.png";
var imgAnn = new ImageAnnotation(
    1,
    new Rectangle(600, 700, 750, 300),
    imgUrl
);

// Placeholder: add the annotation to the manager and load the annotation XML back into the viewer using the current API.

JavaScript で

1. YourController が利用可能であることを確認します。 2. SetNote で画像パスを設定して新しい ImageAnnotation を作成します。 3. アノテーションを追加して描画し、ドキュメント上に表示させます。

JavaScript
function ImageStamp() {
    if (null != objctlDoc.YourController()) {
        var objStampImage = new ImageAnnotation({ left: 200, top: 200, width: 260, height: 55 });
        objctlDoc.YourController().AddAnnotation(null, objStampImage, null);

        objStampImage.SetNote('/images/Approved_Stamp.png');
        objStampImage.Paint();
    }
}

Word ドキュメントのカスタムフォント

WordConfig クラスの FontFolders プロパティは、アプリケーションがフォントを検索するカスタムディレクトリを指定します。これは、システムのデフォルトフォントディレクトリにインストールされていないフォントに依存する Word ドキュメントを処理する際に特に有用です。

Usage
var config = new WordConfig
{
    FontFolders = new string[] { "C:\\CustomFonts", "D:\\SharedFonts" }
};

Doconut 25.2.0 の重要な更新

すべてのプロジェクトで System.Text.Json パッケージをバージョン 8.0.5 に更新することが不可欠です。この更新は、最新機能との互換性を確保し、重要なセキュリティ改善に対処するために重要です。

メールエンコーディング

EmailConfig クラスの EmailEncoding プロパティは、メールの件名と本文の両方に推奨されるエンコーディングを指定します。

Usage
var emailConfig = new EmailConfig {
    EmailEncoding = Encoding.UTF8 // Set preferred email encoding
};

件名と本文のエンコーディング

EmailConfig クラスの SubjectEncoding と BodyEncoding プロパティは、それぞれメールの件名と本文に使用されるエンコーディングを定義します。

Usage
var emailConfig = new EmailConfig {
    SubjectEncoding = Encoding.UTF8, // Set encoding for the subject
    BodyEncoding = Encoding.UTF8     // Set encoding for the body
};

Word Viewer カルチャーサポート

WordConfig クラスの DocumentCulture プロパティを使用すると、DOC および DOCX ファイルのカルチャーを明示的に定義できます。これにより、日付、通貨、数値などのローカライズされたコンテンツが Microsoft Word と同じように正確に表示されます。特に、特定の書式設定要件を持つ言語に便利です。

Usage
var config = new WordConfig { DocumentCulture = "he-IL" }; // Hebrew (Israel)
var config = new WordConfig { DocumentCulture = "ar-SA" }; // Arabic (Saudi Arabia)
var config = new WordConfig { DocumentCulture = "th-TH" }; // Thai (Thailand)
var config = new WordConfig { DocumentCulture = "ja-JP" }; // Japanese (Japan)