admin管理员组文章数量:1419611
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. .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.
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.
Share Improve this question asked Apr 5, 2014 at 0:37 B. Adam RussellB. Adam Russell 1015 bronze badges 4- Hey! I'm looking for a similar fix to PDF.js. Were you ever able to find something to improve this selection issue? Crocodoc handles this by wrapping grouped text in a div and generally works well, but I haven't seen an implementation of this for PDF.js (just a lot of talk about it). Thanks! – trnelson Commented Jun 10, 2014 at 3:18
- i also going through similar issue .Any resolutions ? – ramoh Commented Jun 13, 2014 at 10:17
- sorry for the late response. It's kind of lame, but what I ended up doing was creating empty divs between large gaps of text. This way, the selection is usually over some absolutely positioned div. It seems to work reasonably well. – B. Adam Russell Commented Jun 29, 2014 at 20:11
- see also github./mozilla/pdf.js/pull/6663 – async5 Commented Jan 29, 2018 at 20:24
4 Answers
Reset to default 1Fixed: just add height:200px to
.textLayer > div {height:200px;}
in viewer.css
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 })
In the pdf.js
file, search for function appendText
and add
textDiv.className = "hitext";
below
var textDiv = document.createElement('div');
Now add this to your custom js file:
window.addEventListener('mousedown', function mouseup(evt) {
if($(".hitext:hover").length==0) //To check if the cursor is hovering over the text
{
//Selection is disabled using CSS if the mousedown event was triggered when the cursor was not over the text
$(".hitext").css({"-webkit-touch-callout": "none", "-webkit-user-select": "none", "-khtml-user-select": "none", "-moz-user-select": "none", "-ms-user-select": "none", "user-select": "none"});
}
else
{
$(".hitext").css({"-webkit-touch-callout": "text", "-webkit-user-select": "text", "-khtml-user-select": "text", "-moz-user-select": "text", "-ms-user-select": "text", "user-select": "text"});
}
});
in web\viewer.css file add height:200px; :
.textLayer > div {height:200px;}
本文标签:
版权声明:本文标题:javascript - Prevent text selection from 'jumping' to top when dragging over whitespace in pdf.js - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745317277a2653210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论