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("替换文本完成...");
}

替换后的效果

相关推荐
denggun123454 小时前
PDF解析 Mineru
pdf
10mAh4 小时前
【PaddleOCR】扫描版 PDF 无法复制、RAG 检索为空怎么解决?——OCR 解析与版面还原实战
前端·pdf·ocr
慧都小妮子1 天前
PDF图片提取总“褪色“?Aspose.PDF 多层级提取能力详解
pdf·c#·.net·图片处理·文档处理·色彩空间
SamChan901 天前
PDF翻译中的并发控制:用Semaphore防止API限流与资源耗尽
java·jvm·pdf
ilvcn2 天前
在线 PDF 翻译工具实测:整份翻译保留表格版式,长文档处理方案
pdf
accept 99%2 天前
python版提取 PDF 的常用第三方库与工具
开发语言·python·pdf
AmyLin_20013 天前
PDF 色彩保真工程实践【6】怎么证明“真的无损“?——SHA-256 校验与三个真实踩坑
c++·pdf·内存·sdk·调试·印刷
zyplayer-doc3 天前
zyplayer-doc企业知识库能做什么:从文档创建、权限管理到AI问答的完整能力
大数据·javascript·数据库·人工智能·pdf·word
小短腿乄3 天前
java实现pdf加水印+签名
java·开发语言·pdf
gb42152873 天前
python中unstructured库和langchain-unstructured库在解析pdf文件的时候的区别?
python·langchain·pdf