JS Plugin to avoid copy from pdf

1.7k Views Asked by At

I am looking for a JS Plugin that let me to show 1. PDF Document in Web browser 2. (Most Important)Text in that PDF must not be copied by other

I have tried using PDFObject that allowed me to embed PDF Document into my HTML document here is a code

 <div id="pdf" style="height: 500px;">
<script>
    var options = {
    height: "500px",
    pdfOpenParams: {
        view: 'FitBV,left',
        pagemode: 'bookmarks',
        search: '',
        allowcopy:false //doesnot exist
    }
};

    PDFObject.embed("sample-3pp.pdf",document.getElementById("pdf"),options)
</script>

in this 'allowcopy' parameter doesnot exist in acrobat sdk (parameters for opening documentation) i am looking for such kind of a usecase/parameter that puts to be false and someone cannot copy my content.

1

There are 1 best solutions below

0
On

Well you can do 2 things to prevent others to copy your PDF content.

1. Use a webview/iframe for the PDF.
There are a lot of tools online that will also give you a option to protect your pdf online. Just google it. For example: flippingbook, locklizard and similer third-party tools.

OR

2. Disable copy/cut via JAVASCRIPT and also disable seleting with CSS...

The javascript to disable copy/cut functions (for the whole body tag):

<script type="text/javascript">
  $(document).ready(function () {
      $('body').bind('cut copy', function (e) {
          e.preventDefault();
      });
  });
</script>

The css that disables the SELECTING of content (for the class noSelect):

.noSelect {
  -webkit-touch-callout: none;
    -webkit-user-select: none;
     -khtml-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
}

I think this is what you were searching. I hope this will help you further.

Update: Also adding "#toolbar=0&navpanes=0&scrollbar=0" to the embed pdf would disable download/save buttons. Disabling the right-click would also be a TODO here since users will probably still be able to download if it is allowed to use the right-click... You can do this with JAVASCRIPT:

 window.addEventListener('contextmenu', function (e) {
  e.preventDefault();
}, false);

However smart users can still bypass this option...