Firefox printing PDF in an iframe throws an error

Need help

I need to load PDF into iframe while clicking and then call print dialog on it.

I have such code:

$('.print').click(function () {
   var iframe = '<iframe src="test.pdf" id="print-iframe" name="print-iframe"></iframe>';
   $('body').append(iframe);
   window.frames["print-iframe"].focus();
   window.frames["print-iframe"].print();
});

It works perfectly in Chrome. But in Firefox I have such an error: Error: Permission denied to access property 'print'.

How can I work around it? Thanks!

Answers:

Answer

On recent versions of Firefox (since 19), you have to disable the bugged and native PDF viewer (pdf.js) in about:config. Set the pdfjs.disabled property to true and you will see the print window appearing using your script.

If there's a download starting, set the plugin.disable_full_page_plugin_for_types property to application/pdf.

Answer

This is error of Src in iframe with full url src="domain.com/file.pdf"

you can try

$('.print').click(function () {

  var domain = location.protocol + "//" + location.host;
  var iframe = '<iframe src="'+domain+'/test.pdf" id="print-iframe" name="print-iframe"></iframe>';
  $('body').append(iframe);
  window.frames["print-iframe"].focus();
  window.frames["print-iframe"].print();
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.