Pdf.js: Is it possible to prevent from copying text selection?

Created on 17 Jan 2017  路  10Comments  路  Source: mozilla/pdf.js

Hi,

I would like to know if it is possible to prevent user from copying selected text into the PDF?

Thanks for your help.

S.

Most helpful comment

Why not disable selection of text layer from CSS?

.textLayer {
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none; /* Safari */
   -khtml-user-select: none; /* Konqueror HTML */
     -moz-user-select: none; /* Firefox */
      -ms-user-select: none; /* Internet Explorer/Edge */
          user-select: none; /* Non-prefixed version, currently
                                supported by Chrome and Opera */
}

of course, it's not bulletproof, but the web isn't in the end, is it? ;)

And keeps search working

All 10 comments

You can disable text layer rendering by setting e.g., https://github.com/mozilla/pdf.js/blob/master/web/default_preferences.json#L12 to true.

Thank you @timvandermeij. It is working.
I cannot find the option to unactivate print and download functions.
Is there a clean way to do it or do I need to comment out the HTML code?

Thanks for your help.

There is no option for that in the default viewer, so you'll have to implement that yourself.

@timvandermeij thank you for your answer.

@timvandermeij disabling text layer rendering is a good workaround to prevent from copying text but unfortunately the search function loses the highlight feature. Is there an other workaround where I can prevent from copying selected text but still able to highlight searchs into PDF?

Thanks for your help.

S.

No, the search function directly depends on the text layer.

Why not disable selection of text layer from CSS?

.textLayer {
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none; /* Safari */
   -khtml-user-select: none; /* Konqueror HTML */
     -moz-user-select: none; /* Firefox */
      -ms-user-select: none; /* Internet Explorer/Edge */
          user-select: none; /* Non-prefixed version, currently
                                supported by Chrome and Opera */
}

of course, it's not bulletproof, but the web isn't in the end, is it? ;)

And keeps search working

Thanks @sielay, it is what I have done.

for the question: I cannot find the option to unactivate print and download functions.
you can try this

<script type="text/javascript"> document.getElementById("secondaryOpenFile").style.display = "none"; document.getElementById("openFile").style.display = "none"; document.getElementById("secondaryPrint").style.display = "none"; document.getElementById("print").style.display = "none"; document.getElementById("secondaryDownload").style.display = "none"; document.getElementById("download").style.display = "none"; </script>

in your viewer.html file

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexP3 picture AlexP3  路  3Comments

brandonros picture brandonros  路  3Comments

liuzhen2008 picture liuzhen2008  路  4Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments

timvandermeij picture timvandermeij  路  4Comments