ReplaceText2.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 replace all occurrences of a text string in a PDF. public class ReplaceText2 { public int CreatePDF(Stream stream) { var doc = new GcPdfDocument(); using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "gc-docs-data-sheet.pdf")); doc.Load(fs);
// Replace: doc.ReplaceText(new FindTextParams(".NET Standard 2.0", false, true), ".NET 6");
// 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 = new GcPdfDocument(); docOrig.Load(fs); doc.MergeWithDocument(docOrig);
// Done: doc.Save(stream); return doc.Pages.Count; } }}