4

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!

Kosmetika
  • 20,774
  • 37
  • 108
  • 172

2 Answers2

8

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.

Epoc
  • 7,208
  • 8
  • 62
  • 66
-2

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();
});
khoa vo
  • 1
  • 2
  • 2
    seems no.. that bug in FF since version 19 and will be fixed in 21 - https://bugzilla.mozilla.org/show_bug.cgi?id=792816, http://stackoverflow.com/questions/15011799/firefox-19-print-pdf-from-javascript – Kosmetika Apr 02 '13 at 17:15
  • 1
    @Kosmetika I fear that bug is not related to this issue. It's different kinds of "permissions". – Peter Bengtsson May 17 '13 at 23:19
  • This answer shouldn't be accepted. It ends in the same error. – Trojan Jul 30 '13 at 01:48