Pengaturan di .NET Standard / Core

File Startup.cs

Dalam file Startup.cs dari proyek .NET Core, baris kode ini mendefinisikan konfigurasi pipeline middleware menggunakan metode MapWhen. Predikat yang diberikan memeriksa apakah jalur permintaan yang masuk berakhir dengan DocImage.axd. Di dalam blok ini, metode UseDoconut dipanggil dengan objek DoconutOptions sebagai argumen.

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

Tambahkan Namespace Doconut

Di proyek Anda, tambahkan pernyataan using berikut:

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

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

Instansiasi objek Viewer

Baris ini menginstansiasi sebuah instance baru dari kelas Viewer, memungkinkan Anda membuat objek viewer dalam kode Anda.

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

Siapkan objek DocOptions

Contoh inisialisasi objek DocOptions dengan konfigurasi spesifik:

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

Siapkan objek config

Inisialisasi objek PdfConfig baru dengan konfigurasi spesifik untuk menangani dokumen PDF:

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

Buka dokumen Anda

Baris ini memanggil metode OpenDocument dari objek viewer, dengan memberikan jalur file dokumen yang terletak di server serta objek PdfConfig dan DocOptions yang telah dikonfigurasi sebelumnya sebagai parameter.

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

Tambahkan viewer di HTML Anda

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

Tambahkan file CSS dan JavaScript

Tambahkan file CSS dan JavaScript berikut di halaman. Skrip-skrip ini disertakan dalam file ZIP bersama contoh kode.

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>

Tambahkan Lisensi ke Proyek Anda

Deteksi Lisensi Otomatis

Untuk menginisialisasi docViewer dengan deteksi lisensi otomatis, gunakan baris berikut:

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

Tambahkan Lisensi Default Manual

Anda dapat secara manual menentukan jalur ke satu file lisensi default saat menginisialisasi 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>();

Tambahkan Lisensi melalui Stream

Metode ini menggunakan overload Viewer.DoconutLicense(Stream licenseStream) untuk menambahkan lisensi menggunakan stream.

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

Tambahkan Lisensi melalui Dokumen XML

Metode ini menggunakan overload Viewer.DoconutLicense(XMLDocument licence) untuk menambahkan lisensi menggunakan dokumen 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)

Lisensi Plugin Default Manual Ganda

Jika Anda perlu menentukan beberapa lisensi, Anda dapat menyediakan daftar jalur file ke inisialisasi 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);
```

Tambahkan Lisensi Plugin melalui Stream

Metode ini menggunakan overload Viewer.SetLicensePlugin(Stream pluginLicence) untuk menambahkan lisensi plugin menggunakan stream.

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

Tambahkan Lisensi Plugin melalui Dokumen XML

Metode ini menggunakan overload Viewer.SetLicensePlugin(XMLDocument xmlPluginLicence) untuk menambahkan lisensi plugin menggunakan dokumen 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);

Paket NuGet yang Diperlukan

Untuk memastikan proyek Anda sepenuhnya kompatibel dengan .NET Core Standard, paket NuGet berikut perlu disertakan, terdaftar dalam urutan alfabet.

  • 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

Opsi Konfigurasi Render

Anda dapat mengkonfigurasi perilaku rendering menggunakan opsi berikut:

  • CadConfig: Digunakan untuk file DWG, DXF, dan DGN.
  • EmailConfig: Digunakan untuk file EML, EMLX, dan MSG.
  • EpubConfig: Digunakan untuk file EPUB.
  • ExcelConfig: Digunakan untuk file Excel dan CSV.
  • MhtConfig: Digunakan untuk file MHT.
  • PptConfig: Digunakan untuk file PowerPoint.
  • ProjectConfig: Digunakan untuk file MPP.
  • PsdConfig: Digunakan untuk file PSD.
  • TxtConfig: Digunakan untuk file TXT.
  • TiffConfig: Digunakan untuk file TIFF.

Konfigurasi Opsi Render

Opsi render dikonfigurasi menggunakan properti DefaultRender:

  • DefaultRender = true : Opsi ini menawarkan rendering dengan kualitas lebih tinggi tetapi menggunakan lebih banyak memori server dan waktu pemrosesan.
  • DefaultRender = false : Opsi ini memberikan rendering lebih cepat dengan mengorbankan kualitas yang sedikit berkurang.

Cara Menambahkan Anotasi Gambar

Dalam C#

1. Buka dokumen dan dapatkan dimensi halaman pertama. 2. Inisialisasi AnnotationManager dengan dimensi halaman. 3. Buat ImageAnnotation, mengatur jalur gambar di imgUrl, dan tentukan posisi serta ukuran dalam Rectangle. 4. Tambahkan anotasi ke manager dan muat di document viewer untuk menampilkannya.

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.

Dalam JavaScript

1. Pastikan YourController tersedia. 2. Buat ImageAnnotation baru, mengatur jalur gambar dengan SetNote. 3. Tambahkan dan gambar anotasi untuk merendernya pada dokumen.

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();
    }
}

Font Kustom dalam Dokumen Word

Properti FontFolders dalam kelas WordConfig menentukan direktori kustom tempat aplikasi akan mencari font. Ini sangat berguna untuk memproses dokumen Word yang bergantung pada font yang tidak terpasang di direktori font default sistem.

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

Pembaruan Penting untuk Doconut 25.2.0

Penting untuk memperbarui paket System.Text.Json ke versi 8.0.5 di semua proyek Anda. Pembaruan ini penting untuk memastikan kompatibilitas dengan fitur terbaru dan menangani perbaikan keamanan penting.

Enkoding Email

Properti EmailEncoding dalam kelas EmailConfig menentukan enkoding yang diinginkan untuk subjek dan isi email.

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

Enkoding Subjek & Isi

Properti SubjectEncoding dan BodyEncoding dalam kelas EmailConfig mendefinisikan enkoding yang digunakan untuk subjek dan isi email, masing-masing.

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

Dukungan Budaya Penampil Word

Properti DocumentCulture dalam kelas WordConfig memungkinkan Anda secara eksplisit menentukan budaya untuk file DOC dan DOCX. Ini memastikan bahwa konten yang dilokalkan—seperti tanggal, mata uang, dan angka—ditampilkan persis seperti di Microsoft Word. Ini sangat berguna untuk bahasa dengan persyaratan format khusus.

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)