//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingGrapeCity.Documents.Pdf; namespaceDsPdfWeb.Demos{// This example shows how to find and replace all occurrences of a text string in a PDF.publicclassReplaceText {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "LeaseAgreementDemo.pdf")); doc.Load(fs); // Replace:// "Jane Donahue" -> "John Doe"// "(123)098-7654" -> "(007)123-4567"// "janed@example.com" -> "johnd@example.com" doc.ReplaceText(newFindTextParams("Jane Donahue", false, true), "John Doe"); doc.ReplaceText(newFindTextParams("(123)098-7654", false, true), "(007)123-4567"); doc.ReplaceText(newFindTextParams("janed@example.com", false, true), "johnd@example.com");// "13-Dec-20 22:16:00" -> date now// "13-Dec-22 22:16:00" -> date now + 2 yearsvar termStart = Common.Util.TimeNow();var termEnd = Common.Util.TimeNow() + TimeSpan.FromDays(365 * 2); doc.ReplaceText(newFindTextParams("13-Dec-20 22:16:00", false, true), termStart.ToString("yyyy-MM-dd") + " " + termStart.ToString("HH:mm")); doc.ReplaceText(newFindTextParams("13-Dec-22 22:16:00", false, true), termEnd.ToString("yyyy-MM-dd") + " " + termEnd.ToString("HH:mm")); // "condominium" -> "flat"var font = GrapeCity.Documents.Text.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Bold.ttf")); doc.ReplaceText(newFindTextParams("condominium", true, false), "flat", null, font); // For reference, append the original PDF:Common.Util.AddNote("For reference, the following pages contain a copy of the original unmodified PDF.", doc.NewPage());var docOrig = newGcPdfDocument(); docOrig.Load(fs); doc.MergeWithDocument(docOrig); // Done: doc.Save(stream);return doc.Pages.Count; } }}