Reputation: 159
I am using pdf viewer chrome extension in chrome browser. Installed from here. https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm the extension uses pdfJS library to load the pdf present in the html
I have coordinates of a text and I want to use the coordinates to navigate and highlight the given text in the pdf.
Is there any workable solution available ?
Appreciate your reponse..
Upvotes: 1
Views: 2304
Reputation: 11739
Extensions when run from an html page are limited for conversation since they run in binary applications on the downloaded PDF that is outside of the browser.
So in this usage case we need to ensure certain settings are known
so 1st advise the user to remove auto "Show previous position" and change that to "Default" and ensure related "Disable range requests" is unchecked:-
Now a URL should go where the link is set so On this html page I can try https://stackoverflow.com/questions/73398497/navigate-and-highlight-a-text-in-pdf-rendered-by-pdfjs-library/73409029/#:~:text=Is%20there%20any%20workable%20solution%20available%20%3F
For the PDF that will NOT work because its NOT in the web page, but we can try to specify (will not always work, for any or all user browsers) https://africau.edu/images/default/sample.pdf#page=1&zoom=1000,195,625
Why 195,625 ? We can see from a text extraction the letters start at 195+ and top Left will be roughly 167 down from 792 at top.
<char bbox="195.97997 164.354 200.97997 178.09401" x="195.97997" y="175.104" c="z"/>
<char bbox="200.97997 164.354 205.97997 178.09401" x="200.97997" y="175.104" c="z"/>
<char bbox="205.97997 164.354 210.97997 178.09401" x="205.97997" y="175.104" c="z"/>
<char bbox="210.97997 164.354 215.97997 178.09401" x="210.97997" y="175.104" c="z"/>
<char bbox="215.97997 164.354 220.97997 178.09401" x="215.97997" y="175.104" c="z"/>
An alternative syntax is http://africau.edu/images/default/sample.pdf#page=1&zoom=FitR,195,625,100,100
however I find that erratic see https://github.com/mozilla/pdf.js/issues/10772
Independent of position we can highlight a search word, however there are many more oddities.
So whatever the zoom, here the left edge where the string search starts from must be visible, and we cannot set the viewport as it wraps around the whole file to find the first matching block of characters. (here it started on top left of page 2 then warped back to page 1.)
Related there are better optional search setting so try both
https://mozilla.github.io/pdf.js/web/viewer.html#page=3&search=%22activation%20%20%20%20record%22&phrase=false&zoom=500
https://mozilla.github.io/pdf.js/web/viewer.html#page=3&search=%22activation%20%20%20%20record%22&phrase=true&zoom=500
Upvotes: 1