1

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

4

1 回答 1

3

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

您可以使用文档链接来搜索和替换 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");
于 2016-03-29T04:50:32.290 回答