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

替换后的效果

相关推荐
海带紫菜菠萝汤11 小时前
企业批量PDF翻译方案:从选型到部署的完整指南
人工智能·算法·pdf
蓝创工坊Blue Foundry13 小时前
发票、凭证和对账单怎么整理成 Excel?先定义字段,再逐项复核
pdf·ocr·excel·文心一言·paddlepaddle
求真学习14 小时前
字节跳动Dolphin-v2:数字 PDF 拆开读、拍照文档整页读,自建拍照文档集平均编辑距离较原始 Dolphin降低约 91%
pdf·ocr·pdf解析·字节跳动·文档解析·dolphin-v2
CodexDave14 小时前
Python 自动化接单实战(四):PDF 批量提取先识别文本层还是扫描件
python·pdf·自动化·ocr·python自动化·文档处理·pdf提取
爱昏羔1 天前
上篇:从PDF到向量库 — 物流行业RAG系统的知识库构建全解析
python·langchain·pdf·agent·rag
AI导出鸭PC端2 天前
手机deepseek怎么导出pdf AI导出鸭
人工智能·pdf
蓝创工坊Blue Foundry2 天前
PaddleOCR 本地部署教程:小模型 OCR 如何完成字段提取到 Excel
pdf·自动化·ocr·excel·paddlepaddle·paddle
蓝创工坊Blue Foundry3 天前
个人藏书太多怎么整理?用 OCR 字段提取汇总成电子书目
pdf·ocr·excel·文心一言·paddlepaddle·paddle
蓝创工坊Blue Foundry4 天前
扫描件批量转 Excel:先确认要整表还原还是字段汇总
python·pdf·ocr·excel
审小匠OpenCPAi4 天前
审计票据与财报 PDF 怎么识别?通用 OCR、表格结构识别与多模态大模型的精度对比
pdf·ocr·审计