GroupDocs.Redaction for .NET 26.6 đã có sẵn. Bản phát hành này giúp việc mở tài liệu từ luồng và tệp với định dạng rõ ràng trở nên dễ dàng hơn, đồng thời giới thiệu API vẽ mới không phụ thuộc vào System.Drawing để cải thiện khả năng tương thích đa nền tảng.

Các bản sửa lỗi và cải tiến

  • [Enhancement] Xác định loại tệp khi mở tài liệu từ luồng hoặc đường dẫn tệp. (REDACTIONNET-572)
  • [Enhancement] Di chuyển ra khỏi System.Drawing để nâng cao khả năng tương thích đa nền tảng. (REDACTIONNET-799)

Có gì mới?

Bản phát hành này tập trung vào hai lĩnh vực giúp đơn giản hoá việc tích hợp và chuẩn bị API cho hỗ trợ nền tảng rộng hơn.

Xác định định dạng tài liệu bằng LoadOptions.FileType

Khi mở một tài liệu, GroupDocs.Redaction thường tự động phát hiện định dạng của nó. Điều này hoạt động tốt với các tệp có phần mở rộng đúng, nhưng có thể thất bại đối với luồng không có tên tệp hoặc khi phần mở rộng không khớp với nội dung thực tế.

Phiên bản 26.6 bổ sung thuộc tính LoadOptions.FileType và một hàm khởi tạo LoadOptions(FileType). Đặt FileType thành một hằng số được hỗ trợ như FileType.DOCX hoặc FileType.PDF, và thư viện sẽ mở tài liệu bằng định dạng đó mà không thực hiện quá trình phát hiện định dạng nhị phân. Hành vi mặc định không thay đổi khi FileType không được chỉ định hoặc vẫn là FileType.Unknown.

Các kiểu vẽ đa nền tảng trong GroupDocs.Redaction.Options.Drawing

Một số tùy chọn redaction trước đây dựa vào các kiểu của System.Drawing (Color, Point, Size, Rectangle, Font). Các kiểu này không có trên mọi nền tảng và có thể gây khó khăn khi triển khai trên Linux và môi trường container.

Namespace mới GroupDocs.Redaction.Options.Drawing cung cấp các kiểu Color, Point, Size, Rectangle, FontFontStyle để sử dụng trong API công khai. Các overload mới chấp nhận các kiểu này trong ReplacementOptions, RegionReplacementOptions, ImageAreaRedaction, PageAreaFilter, TextFragment và các lớp liên quan.

Mã hiện có sử dụng System.Drawing vẫn biên dịch và chạy được. Các thành viên tương ứng được đánh dấu là obsolete và nên được chuyển sang các kiểu mới trong các bản cập nhật tương lai.

Thay đổi API công khai

Được thêm vào

  • Thuộc tính LoadOptions.FileType
  • Hàm khởi tạo LoadOptions(FileType fileType)
  • Các kiểu vẽ trong GroupDocs.Redaction.Options.Drawing: Color, Point, Size, Rectangle, Font, FontStyle
  • Các overload mới chấp nhận các kiểu GroupDocs.Redaction.Options.Drawing

Đánh dấu obsolete

  • ReplacementOptions.BoxColor — sử dụng ReplacementOptions.BoxFillColor thay thế
  • ReplacementOptions(System.Drawing.Color) — sử dụng ReplacementOptions(GroupDocs.Redaction.Options.Drawing.Color) thay thế
  • RegionReplacementOptions.FillColor — sử dụng RegionReplacementOptions.AreaFillColor thay thế
  • RegionReplacementOptions.Size — sử dụng RegionReplacementOptions.AreaSize thay thế
  • RegionReplacementOptions(System.Drawing.Color, System.Drawing.Size) — sử dụng overload với GroupDocs.Redaction.Options.Drawing.ColorGroupDocs.Redaction.Options.Drawing.Size thay thế
  • RegionReplacementOptions(System.Drawing.Color, System.Drawing.Font, string) — sử dụng overload với GroupDocs.Redaction.Options.Drawing.ColorGroupDocs.Redaction.Options.Drawing.Font thay thế
  • ImageAreaRedaction.TopLeft — sử dụng ImageAreaRedaction.TopLeftPosition thay thế
  • ImageAreaRedaction(System.Drawing.Point, RegionReplacementOptions) — sử dụng overload với GroupDocs.Redaction.Options.Drawing.Point thay thế
  • PageAreaFilter.Rectangle — sử dụng PageAreaFilter.AreaRectangle thay thế
  • PageAreaFilter(System.Drawing.Point, System.Drawing.Size) — sử dụng overload với GroupDocs.Redaction.Options.Drawing.PointGroupDocs.Redaction.Options.Drawing.Size thay thế
  • TextFragment.Rectangle — sử dụng TextFragment.BoundingRectangle thay thế
  • TextFragment(string, System.Drawing.Rectangle) — sử dụng TextFragment(string, GroupDocs.Redaction.Options.Drawing.Rectangle) thay thế
  • IImageFormatInstance.EditArea(System.Drawing.Point, RegionReplacementOptions) — sử dụng overload với GroupDocs.Redaction.Options.Drawing.Point thay thế

Ví dụ mã

Mở tài liệu với loại tệp rõ ràng

using System.IO;
using GroupDocs.Redaction.Options;
using GroupDocs.Redaction.Redactions;

using (Stream stream = File.OpenRead("sample.docx"))
{
    using (Redactor redactor = new Redactor(stream, new LoadOptions(FileType.DOCX)))
    {
        redactor.Apply(new DeleteAnnotationRedaction());
        redactor.Save();
    }
}

using (Redactor redactor = new Redactor("sample.pdf", new LoadOptions(FileType.PDF)))
{
    redactor.Apply(new ExactPhraseRedaction("Test", new ReplacementOptions("[redacted]")));
    redactor.Save();
}

Sử dụng GroupDocs.Redaction.Options.Drawing thay vì System.Drawing

using GroupDocs.Redaction.Options.Drawing;
using GroupDocs.Redaction.Redactions;

// Trước đây: new ReplacementOptions(System.Drawing.Color.Red)
using (Redactor redactor = new Redactor("sample.docx"))
{
    redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(Color.Red)));
    redactor.Save();
}

// Trước đây: new ImageAreaRedaction(new System.Drawing.Point(516, 311),
//     new RegionReplacementOptions(System.Drawing.Color.Blue, new System.Drawing.Size(170, 35)))
using (Redactor redactor = new Redactor("sample.jpg"))
{
    redactor.Apply(new ImageAreaRedaction(new Point(516, 311),
        new RegionReplacementOptions(Color.Blue, new Size(170, 35))));
    redactor.Save();
}

Cách nhận bản cập nhật

  • NuGet – Nâng cấp lên gói GroupDocs.Redaction for .NET mới nhất qua NuGet
  • Tải trực tiếp – Tải các assembly của GroupDocs.Redaction từ trang GroupDocs.Redaction for .NET 26.6

Tìm hiểu thêm