I've built a search engine to find the most relevant phrases inside a document, after a user text search. After my processing I have a list of phrases texts. What I need now is to display them to the user, showing the original source PDF and scrolling it to the page where the original phrase is found. The best case scenario would be to highlight it, but for now Scrolling is enough.
I'm using PHP and Javascript.
Can anyone point me a way to do this? Is there any framework available?
Any tips are welcome.
There is an excellent JavaScript library for embedding PDFs called pdf.js. A demo can be found here
Out of the box, I don't think it has the highlighting and scrolling functionality you're looking for. However, it looks like someone may have figured out how to do it here
If you are using Acrobat Reader to display the file in the browser, then you could use Acrobat Reader URL parameters.
Example:
http://example.org/doc.pdf#page=3
There is also a post about how to embed a PDF document in a web page using Acrobat Reader
If you cannot asume that your users will use Adobe Acrobat Reader, then another option could be to use a library on the server side, then create a temporary PDF file that includes an "OpenAction" redirecting to your target page, and return that temporary file instead. The code for including this OpenAction will depend on the library that you decide to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With