Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent text selection from 'jumping' to top when dragging over whitespace in pdf.js

I'm using pdf.js with text selection.

So pdf.js creates a bunch of absolute positioned divs containing the various text from the pdf to supply text selection.

While dragging to select the text, the selection jumps to selecting everything to the top of the text, if you continue your selection into areas that are not text (like areas between paragraphs).

If you go to their example you can see what I'm describing. Try selecting text over several paragraphs in the left column and you'll see the selection "flicker" to selecting everything to top. http://mozilla.github.io/pdf.js/web/viewer.html

Any ideas on how to prevent this from happening? It is very distracting.

I think it has something to do with all of the divs holding the text being absolute.

like image 429
B. Adam Russell Avatar asked Apr 05 '14 00:04

B. Adam Russell


2 Answers

Fixed: just add height:200px to

.textLayer > div {height:200px;}

in viewer.css

like image 200
Faizan Tahir Avatar answered Oct 06 '22 00:10

Faizan Tahir


This is a bit old but still might be useful for some people. Setting textLayerMode to 2 should fix that issue.

Example:

new PDFViewer({ ...otherProps, textLayerMode: 2 })
like image 30
Rani Avatar answered Oct 05 '22 23:10

Rani