【问题标题】:Aspose.PDF How Replace replace text on PDF page to all upper caseAspose.PDF如何将PDF页面上的替换文本全部替换为大写
【发布时间】:2016-07-13 16:41:35
【问题描述】:

我正在尝试使用 Aspose.PDF for .Net 将特定页面上的文本替换为大写。如果有人可以提供任何帮助,那就太好了。谢谢。

【问题讨论】:

    标签: aspose aspose.pdf


    【解决方案1】:

    我的名字是 Tilal Ahmad,我是 Aspose 的开发人员传道者。

    您可以使用documentation link 搜索和替换 PDF 文档特定页面上的文本。您应该按照文档底部的建议为特定页面索引调用 Accept 方法。此外,为了用大写替换文本,您可以使用 String 对象的 ToUpper() 方法,如下所示。

    ....
    textFragment.Text = textFragment.Text.ToUpper();
    ....
    

    编辑:更改特定 PDF 页面上文本大小写的示例代码

    //open document
    Document pdfDocument = new Document(myDir + "testAspose.pdf");
    //create TextAbsorber object to find all instances of the input search    phrase
    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("");
    //accept the absorber for all the pages
    pdfDocument.Pages[2].Accept(textFragmentAbsorber);
    //get the extracted text fragments
    TextFragmentCollection textFragmentCollection =   textFragmentAbsorber.TextFragments;
    //loop through the fragments
    foreach (TextFragment textFragment in textFragmentCollection)
    {
        //update text and other properties
        textFragment.Text = textFragment.Text.ToUpper();
    
    }
    
    pdfDocument.Save(myDir+"replacetext_output.pdf");
    

    【讨论】:

    • 这不起作用有两个原因,你的假设是我知道要替换的文本,但我不知道。我只知道页面并想将其转换为大写。您还建议使用 textFragment 类,但该类不支持页面上当然存在的多行字符串,因此也不起作用。
    • @NYTom,请注意,如果我们不将搜索字符串传递给 TextFragmentAbsorber 对象,那么它将搜索指定页面的完整文本作为 TextFragmentCollection,我们可以遍历集合以更改 Textfragment 的大小写。
    • 但是使用那个类的多行问题呢?
    • @NYTom,抱歉延迟回复。如上所述,TextFragmentAbsorber 将获取页面的所有文本(多行)作为 TextFragmentCollection。所以不会有任何多行问题。但是,如果您遇到任何问题,请在 Aspose.Pdf 论坛的相关帖子中分享您的示例 PDF 文档,我们将对其进行调查并为您提供相应的指导。
    • 我正在尝试使用 aspose 替换 pdf 中的大文本,但在行结束后其余文本丢失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多