DeleteText.cs
// 完毕:
using System;
using System.IO;
using System.Drawing;
using System.Text;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Pdf.AcroForms;

namespace DsPdfWeb.Demos
{
    // This example shows how to find and delete all occurrences of a text string in a PDF.
    public class DeleteText
    {
        public int CreatePDF(Stream stream)
        {
            var doc = new GcPdfDocument();
            using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "TimeSheet.pdf"));
            doc.Load(fs);

            // Delete dates and times using regex pattern:
            var ftps = new FindTextParams(@"\d+/\d+/\d+|\d+:\d+| am| pm", false, false, 72, 72, false, true);
            doc.DeleteText(ftps, GrapeCity.Documents.Pdf.TextMap.DeleteTextMode.PreserveSpace);

            // For reference, append the original PDF:
            Common.Util.AddNote("For reference, the following page contains a copy of the original unmodified PDF.", doc.NewPage());
            var docOrig = new GcPdfDocument();
            docOrig.Load(fs);
            doc.MergeWithDocument(docOrig);

            // 完毕:
            doc.Save(stream);
            return doc.Pages.Count;
        }
    }
}