Net9为PDF文字替换,使用Spire.PDF版本10.12.4.1360

如下图,把第一行几个字换掉

Dll版本

替换代码

cs 复制代码
private void ReplaceTextInPage(object sender, RoutedEventArgs e)
{
    string title = "选择文件进行字符串替换...";
    string? pdfFile = FindFile(title);
    if (pdfFile is null)
        return;
    PdfDocument pdfDoc = new PdfDocument(pdfFile);

    // 创建PdfTextReplaceOptions 对象
    PdfTextReplaceOptions textReplaceOptions = new PdfTextReplaceOptions();

    // 指定文本替换的选项
    textReplaceOptions.ReplaceType = PdfTextReplaceOptions.ReplaceActionType.WholeWord;

    //遍历PDF文档所有页面
    for (int i = 0; i < pdfDoc.Pages.Count; i++)
    {
        PdfPageBase page = pdfDoc.Pages[i];

        // 根据页面创建PdfTextReplacer 对象
        PdfTextReplacer textReplacer = new PdfTextReplacer(page);
        textReplacer.Options = textReplaceOptions;

        // 将所有目标文本的出现替换为新文本
        textReplacer.ReplaceAllText("第一行", "行行行");
    }
    string name = Path.GetFileNameWithoutExtension(pdfFile);
    pdfDoc.SaveToFile($"{desktop}\\{name}_替换文本.pdf", FileFormat.PDF);
    System.Windows.MessageBox.Show("替换文本完成...");
}

替换后的效果

相关推荐
chéng ௹2 小时前
vue2 上传pdf,拖拽盖章,下载图片
前端·css·pdf
灰度少爷10 小时前
批量统计PDF页数,统计图像属性
pdf
TOMaster.16 小时前
VBA将PDF文档内容逐行写入Excel
pdf·xpdf-tools·vba导入pdf
winfredzhang1 天前
使用Python 打造多格式文件预览工具 — 图、PDF、Word、Excel 一站式查看
python·pdf·word·excel·照片·查看,zip,复制
geovindu2 天前
vue3: pdf.js 2.16.105 using typescript
javascript·vue.js·typescript·pdf
莫轻言舞2 天前
SpringBoot整合PDF导出功能
spring boot·后端·pdf
geovindu2 天前
vue3: pdf.js5.2.133 using typescript
javascript·vue.js·typescript·pdf
企鹅侠客2 天前
一个开源的快速准确地将 PDF 转换为 markdown工具
pdf·markdown
old_power2 天前
C++使用PoDoFo库处理PDF文件
c++·pdf
开开心心_Every2 天前
手机隐私数据彻底删除工具:回收或弃用手机前防数据恢复
android·windows·python·搜索引擎·智能手机·pdf·音视频