<p>I'm trying to implement search result highlighting for pdfs in a web app. I have the original pdfs, and small png versions that are used in search results. Essentially I'm looking for an api like:</p>

<pre><code>pdf_document.find_offsets('somestring')
# =&gt; { top: 501, left: 100, bottom: 520, right: 150 }, { ... another box ... }, ...
</code></pre>

<p>I know it's possible to get this information out of a pdf because Apple's Preview.app implements this.</p>

<p>Need something that runs on Linux and ideally is open source. I'm aware you can do this with acrobat on windows.</p>

I think you can do this using the Adobe Acrobat SDK, a Linux version of which can be
downloaded for free from Adobe
. You can use this to
extract text from PDFs
and then work out offsets. The PDF can then be highlighted by using the
Acrobat XML highlighting file
. This is used to specify which words in which positions are to be highlighted and is fed to acrobat as follows:
http://example.com/a.pdf#xml=http://example.com/highlightfile.xml