// 完毕:
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 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);
// 完毕:
doc.Save(stream);
return doc.Pages.Count;
}
}
}