Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Comments
Wessel Beulink 29-Oct-15 6:44am    
How are you converting the dbo text to PDF? I did this before with a xml to PDF converter. Using some XML attr. to highlight text but this depends on what kinda converter you use.
Member 12096997 29-Oct-15 7:31am    
i saved file in BLOB format in DB.
Member 12096997 29-Oct-15 7:34am    
& using BLOB i am converting those format to PDF,here is the stackflow link where i shared the code for view the data from DB
http://stackoverflow.com/questions/3871292/how-to-avoid-cannot-redeclare-class-for-2-diffrent-classes-with-same-name

1 solution

You can just embed the pdf into the page

XML
var source = 'ajax.php?InstrumentID='+encodeUriComponent(instrID)+'&catView=pdf';
$('#inputText').append('<object data="'+source+'" type="application/pdf">'+
                        '<embed src="'+source+'" type="application/pdf"/></object>');


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>
 
Share this answer
 
Comments
Member 12096997 29-Oct-15 9:01am    
FIRST THANKS FOR THE COMMENT & now let me try.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900