DeleteText.cs
C# VB
//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.IO;using GrapeCity.Documents.Pdf;
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);
// Done: doc.Save(stream); return doc.Pages.Count; } }}