在 .NET Framework 中设置

Web.config 配置

在 web.config 文件中注册 HttpHandler。

Below IIS 7
<httpHandlers>
  <add verb="GET,POST" path="DocImage.axd" type="Doconut.DocImageHandler, Doconut" />
</httpHandlers>
IIS 7 and above
<handlers>
  <add name="DocImage" verb="GET,POST" path="DocImage.axd" type="Doconut.DocImageHandler, Doconut" />
</handlers>

添加许可证

Doconut 自动检测根文件夹中的许可证,您也可以手动添加。

Manual License Path
var licenseFilePath = Server.MapPath("~/Doconut.Viewer.lic");
var docViewer = new Viewer(licenseFilePath);

web.config 配置

以下配置条目对于 web.config 文件是必需的,以确保与 Doconut 和 .NET Framework 的兼容性。

web.config
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="8.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="MessagePack" publicKeyToken="9c7f9b36b37eaddf" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.140.0" newVersion="2.5.140.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.4.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

必需的 NuGet 包

为确保项目完全兼容 Doconut 和 .NET Framework,需要包含以下 NuGet 包:

  • MessagePack - Version 2.5.140
  • MessagePack.Annotations - Version 2.5.140
  • Microsoft.Bcl.AsyncInterfaces - Version 8.0.0
  • Microsoft.NET.StringTools - Version 17.6.3
  • System.Collections.Immutable - Version 6.0.0
  • System.Drawing.Common - Version 6.0.0
  • System.Memory - Version 4.5.5
  • System.Reflection.Emit - Version 4.7.0
  • System.Reflection.Emit.Lightweight - Version 4.7.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

渲染配置选项

您可以使用以下选项配置渲染行为:

  • 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 文件。
Example usage
var config = new CadConfig { DefaultRender = false }; // or true

Word 文档中的自定义字体

WordConfig 类中的 FontFolders 属性指定应用程序搜索字体的自定义目录。

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

关于 NuGet 包中 AjaxControlToolkit 的更新

我们对 NuGet 包进行了一些更改以提升兼容性。AjaxControlToolkit 将不再包含在内。建议用户手动在项目中安装 AjaxControlToolkit 版本 4.1.50508。

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 查看器区域设置支持

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)