Spire.PDF如何高亮显示PDF文件里搜索到的文本

作者:控件中国网   出处:控件中国网   2015-11-30 15:32:46   阅读:11

这篇文章主要介绍如何在PDF文档内查找和高亮选择的文本,在很多时候客户需要为搜索到的文本设置不同的背景色以区分正常的文本,Spire.PDF控件为开发人员提供了ApplyHighLight(Color highlightColor)方法,该方法专门用于文本的高亮显示,具体参考下面的部分代码:
Highlight-Searched-Texts.png
//load test file
PdfDocument pdf = new PdfDocument("test.pdf");
//highlight searched text with Green
PdfTextFind[] result1 = null;
result1 = pdf.Pages[0].FindText("Spire.PDF").Finds;
foreach (PdfTextFind find in result1)
{
    find.ApplyHighLight(Color.Green);
}
//highlight searched text with Red
PdfTextFind[] result2 = null;
result2 = pdf.Pages[0].FindText(".NET").Finds;
foreach (PdfTextFind find in result2)
{
    find.ApplyHighLight(Color.Red);
}
//save and review
pdf.SaveToFile("result.pdf",FileFormat.PDF);
System.Diagnostics.Process.Start("result.pdf");
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat