.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
};

config 객체 설정

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

렌더 구성 옵션

다음 옵션을 사용하여 렌더링 동작을 구성할 수 있습니다:

  • 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
};

워드 뷰어 문화 지원

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)