使用PHP突出显示pdf中的seacrhed文本 [英] Highlight seacrhed text inside pdf using PHP
本文介绍了使用PHP突出显示pdf中的seacrhed文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个项目,我需要在PDF中突出显示搜索到的关键字。
我正在使用BLOB将文件保存到数据库中。 />
我已经能够阅读特定的pdf,但无法突出显示PDF中的搜索关键字。
I am making a project in which i need to highlight the searched keyword inside the PDF.
I am using BLOB to save the file in database.
I am already able to read the particular pdf but not able to highlight the searched keyword inside PDFs.
推荐答案
你可以将pdf嵌入到页面中
You can just embed the pdf into the page
var source = 'ajax.php?InstrumentID='+encodeUriComponent(instrID)+'&catView=pdf';
('#inputText')。append('< object data = '+ source +' type = application / pdf > 跨度> '+
'< embed src = '+ source +' type = application / pdf / > < / object > ');
('#inputText').append('<object data="'+source+'" type="application/pdf">'+ '<embed src="'+source+'" type="application/pdf"/></object>');
因此,请在pdf文本上方创建一个搜索页面。把你的文本作为innerHTML放在div类中。使用javascript来突出显示div的这个innerhtml
So make a page with your search above the "pdf" text. put your text down as innerHTML inside a div class. Use a javascript to highlight this innerhtml of the div
<pre lang="xml"><script>
function highlight(text)
{
inputText = document.getElementById("inputText")
var innerHTML = inputText.innerHTML
var index = innerHTML.indexOf(text);
if ( index >= 0 )
{
innerHTML = innerHTML.substring(0,index) + "<span class='highlight'>" + innerHTML.substring(index,index+text.length) + "</span>" + innerHTML.substring(index + text.length);
inputText.innerHTML = innerHTML
}
}
</script>
<style>
.highlight
{
background-color:yellow;
}
</style>
<div id="inputText">
"YOUR PFD (BLOB) TEXT"
</div>
</pre>
这篇关于使用PHP突出显示pdf中的seacrhed文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文