在pdf.js中拖动空格时,防止文本选择从“跳转”到顶部

时间:2014-04-05 00:37:33

标签: javascript pdf pdf.js

我正在使用带有文本选择的pdf.js。

所以pdf.js会创建一堆绝对定位的div,其中包含pdf中的各种文本以提供文本选择。

在拖动以选择文本时,如果您继续选择非文本区域(如段落之间的区域),则选择会跳转到选择文本顶部的所有内容。

如果你去他们的榜样,你可以看到我所描述的。尝试在左栏中的几个段落中选择文本,您将看到选择“闪烁”以选择顶部的所有内容。 http://mozilla.github.io/pdf.js/web/viewer.html

有关如何防止这种情况发生的任何想法?这非常令人分心。

我认为它与所有保持文本绝对的div有关。

3 个答案:

答案 0 :(得分:0)

pdf.js文件中,搜索function appendText并添加

textDiv.className = "hitext";

下面

var textDiv = document.createElement('div');

现在将其添加到您的自定义js文件中:

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"}); 
}

}); 

答案 1 :(得分:0)

已修复: 只需将height:200px添加到

.textLayer > div {height:200px;}

在viewer.css中

答案 2 :(得分:0)

这有点旧,但对于某些人可能仍然有用。将textLayerMode设置为2应该可以解决该问题。

示例:

new PDFViewer({ ...otherProps, textLayerMode: 2 })
相关问题