RedactArea.cs
// 
// このコードは、DioDocs for PDF のサンプルの一部として提供されています。
// © MESCIUS inc. All rights reserved.
// 
using System.IO;
using System.Drawing;
using System.Text.RegularExpressions;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Pdf.Annotations;
using GrapeCity.Documents.Pdf.TextMap;
using GrapeCity.Documents.Pdf.AcroForms;

namespace DsPdfWeb.Demos
{
    // このサンプルは、GcPdfDocument.Redact() メソッドの使用法を示します。
    // SlidePages サンプルによって生成された PDF をロードし、
    // 最初のページに墨消し注釈を作成して適用します。
    public class RedactArea
    {
        public int CreatePDF(Stream stream)
        {
            var doc = new GcPdfDocument();
            using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "SlidePages.pdf"));
            // 墨消し注釈(墨消し用にマークされた領域)を含む PDF をロードします。
            doc.Load(fs);

            var redact = new RedactAnnotation()
            {
                Rect = new RectangleF(16, 16, 280, 300),
                Page = doc.Pages[0],
                OverlayText = "このコンテンツは墨消しされています。",
                OverlayFillColor = Color.PaleGoldenrod
            };

            // 墨消しを適用します。
            doc.Redact(redact);

            // PDF ドキュメントを保存します。
            doc.Save(stream);
            return doc.Pages.Count;
        }
    }
}