IRONSOFTWAREHOME
文本查找和替换
using IronPdf;

// Using an existing PDF
var pdf = PdfDocument.FromFile("sample.pdf");

// Parameters
const int pageIndex = 1;
const string oldText = ".NET 6"; // Old text to remove
const string newText = ".NET 7"; // New text to add

// Replace Text on Page
pdf.ReplaceTextOnPage(pageIndex, oldText, newText);

// Save your new PDF
pdf.SaveAs("new_sample.pdf");
Imports IronPdf

' Using an existing PDF
Dim pdf = PdfDocument.FromFile("sample.pdf")

' Parameters
Const pageIndex As Integer = 1
Const oldText As String = ".NET 6" ' Old text to remove
Const newText As String = ".NET 7" ' New text to add

' Replace Text on Page
pdf.ReplaceTextOnPage(pageIndex, oldText, newText)

' Save your new PDF
pdf.SaveAs("new_sample.pdf")
NuGet Download
PM > Install-Package IronPdf
文本查找和替换

文本查找和替换

您可以使用 IronPdf 的 Replace 功能在 PDF 中查找和替换文本。

此代码演示了如何使用 C# 中的 IronPDF 库替换 PDF 文件中的文本。 首先,请确保已通过 NuGet 安装 IronPDF 库。 该代码通过 FromFile 方法加载现有 PDF 文件,使用 ReplaceTextOnPage 替换指定页面上的文本,并将结果保存为新的 PDF 文件。需要指定页码、待替换的文本以及新文本。 最后,使用 SaveAs 保存更改,并打印一条消息以确认操作已完成。

学习如何使用 IronPDF 在 PDF 中查找和替换文本
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 21,105,021版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索 “IronPDF”
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

或在此处下载 Windows 安装程序。

  1. 下载并解压 IronPDF 到您的解决方案目录中的 ~/Libs 之类的位置
  2. 在 Visual Studio 解决方案资源管理器中,右键点击引用。选择浏览,“IronPDF.dll”

$999 起