Highlight a section inside pdf using Pdf.js

I am currently using pdf.js for my project to render pdf. Now there is this difficult task to select a section of a pdf page, taking into account the coordinates

Example

given the boundary section, such as [(31,35),(40,35),(40,40),(31,40)] . I have to highlight this section with the first selection color selected

How to write javascript to actually use pdf.js api to accomplish this task

Is it possible or am I voicing my ambition

+6
source share
3 answers

I found a better way to achieve this, find the point coordinate in the html page

and then subtract from it the coordinate (position) of the div.textLayer to find the coordinate

text in pdf displayed on the Internet.

To find the coordinate of the text in the actual pdf, find the aspect ratio and you

get the actual coordinate

example

if the text displayed on the Internet is 800x900 and the text coordinate

[(31,35),(40,35),(40,40),(31,40)]

and actual PDF size 612x792

find the corresponding area value in the actual pdf like this

(612/(800 / 31)),(792/(900/35))

and do it for all coordinates found online

i.e

(40,35),(40,40),(31,40)

NOTE: -

You might want to check out the PDF.js API called convertToPdfPoint

+3
source

One of the authors of PDF.js, cjones , stated:

No, and that's (highlighting) not like something we would add to pdf.js. That ought to be easy to layer on top of pdf.js.

Source : http://blog.mozilla.org/cjones/2011/07/03/pdf-js-first-milestone/

You will need to implement it yourself if you are interested in using this feature.

+4
source

If the selection of text may be sufficient for your needs, you can find an entry for your decision in SO on text highlighting in PDF.js.

Text is selected through document.getSelection() .

Color adjustment, as you said, can be done with

 <span style="yourColorDefinition"> 

instead

 <span class="hightlight"> 
0
source

Source: https://habr.com/ru/post/920247/


All Articles