open a pdf in a browser and search the text

Jan Mishkin
Jan Mishkin used Ask the Experts™
on
Is there a way to to open a pdf file in a browser and automatically search/highlight(find in file) a given text string? I'm using PHP.

Here is how I open the pdf currently
header("Location: SamplePDF.pdf");

Here is how I would like to open it in a perfect world- something like  
header("Location: SamplePDF.pdf?SearchText=Pizza");

I kknow that the solution(if there is one) is probably far more extensive.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
You can read a PDF file into the PHP script and look for a search string.  But the way PDF is constructed may not be helpful to you.  A reasonable interface might be like this:

<a href="pdfsearch.php?pdf=sample.pdf&search=pizza">Search sample.pdf for pizza</a>

The pdfsearch.php script would do these things:

1. use file_get_contents() to read the file named sample.pdf
2. use REGEX to extract the word 'pizza' from the PDF file.
3. report back whether or not the 'pizza' string was found.

As far as highlighting PDF files goes, I do not have any hope of doing this.  You would need to deconstruct and reconstruct the PDF file.  Adobe sells a product that does this -- Acrobat.  I am not aware of any API that would handle what you want here.

The utility I can see in the pdfsearch.php script is that it could search thousands of PDF files and tell you which ones had pizza.  Not sure if that is useful, but it is certainly possible.

Hope this helps, ~Ray
Jan MishkinIT Manager

Author

Commented:
Thanks Ray. I already have scripts that convert the pds to text and search for strings. I use these scripts to find the correct pdf file to serve to my client. What I needed was the ability to center in on a particular string because the files can be many pages long.

I bet your right that there is no way to do this. I'll give you points if no one else chimes in anyway.
Most Valuable Expert 2011
Top Expert 2016
Commented:
That "center in on a particular string" part is what the REGEX is about.  Regular Expressions and its country cousin strpos() can help you find pieces of a string if you have a fairly well consolidated thought about what you're looking for.  Good luck with it, ~Ray
Jan MishkinIT Manager

Author

Commented:
There is no solution.
Jan MishkinIT Manager

Author

Commented:
http://localhost/test.pdf#search="pizza" Works but you cannot use wildcards and the search string must be the cmplete word

see http://www.wrensoft.com/forum/showthread.php?t=2326

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial