pdf text search not working

Pdf.js search highlight

Rate this article

Share this article

Read pdf.js search highlight for more information.

pdf.js is a JavaScript library that renders Portable Document Format (PDF) files using the web standards-compliance HTML5 Canvas. The project is led by the Mozilla Foundation after Andreas Gal launched it (initially as an experiment) in 2011.

PDF.js can work as a part of a website or of a browser. Originally created as a Firefox extension, it is now included in Mozilla Firefox since 2012 (version 15) and is enabled by default since 2013 (version 19). It is also included in ownCloud, and as a browser extension for Google Chrome, Chromium, Firefox for Android, Pale Moon, and SeaMonkey.

PDF.js renders PDF files using the HTML5 Canvas. To highlight searched text, the method below uses the position of div.textLayer in the HTML page as its reference point.

pdf.js search highlight

Make a PDF search engine with a few clicks

How PDF.js search highlight coordinates work

I found a  way to achieve PDF.js search highlight text. Find the co-ordinate of the point in the HTML page and then subtract the co-ordinate(position) of div.textLayer from it to find the co-ordinate of the text in the pdf displayed online.

In order to find the co-ordinate of the text in actual pdf find the aspect ratio and you would get the actual co-ordinate.

example:

If the PDF displayed online is 800×900 and the text co-ordinate [(31,35),(40,35),(40,40),(31,40)] and the actual pdf size is 612×792 find the appropriate value of the area in actual pdf like this (612/(800 / 31)),(792/(900/35)) and do this way for all co-ordinate found in online, i.e, (40,35),(40,40),(31,40)

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like