2

This code is working fine in Chrome but not in Firefox. It gives a error :

SecurityError: Permission denied to access property "print" on cross-origin object"

Please give me a solution.

<iframe src="myfile.pdf" style="width: 96%; height:500px;" frameborder="0" id="iframe" name="iframe"></iframe>
<button type="button" class="btn btn-default" onclick="print()">Print</button>
function print() {
   jQuery("#iframe").get(0).contentWindow.print();
}
Renan Araújo
  • 3,533
  • 11
  • 39
  • 49
kapil khatri
  • 21
  • 1
  • 2
  • 2
    Possible duplicate of [Print PDF in Firefox](https://stackoverflow.com/questions/33254679/print-pdf-in-firefox) – Scath Jan 02 '18 at 14:18

1 Answers1

1

The problem is the viewer. The embedded viewer causes the cross-origin problem. Try creating your own viewer. That will solve the problem. e.g. from here: https://pspdfkit.com/blog/2019/implement-pdf-viewer-pdf-js/

Or if you need a full featured viewer, you can use the Mozilla one from here: http://mozilla.github.io/pdf.js/web/viewer.html (for this one you will need to download the latest pdf.js and pdf.worker.js implementation). I just did that for a project at work, and it works like a charm.