I have a "Print" button which invokes the following JavaScript
window.frames.myPdfFrame.print();
where "myPdfFrame" refers to an iframe with a PDF for the src.
In Chrome and Firefox 18 (and below) this opens the print dialog as expected, but as of Firefox 19 I get the following error
Error: Permission denied to access property 'print'
I assume this is related to using the embedded PDF viewer released with Firefox 19 rather than the Adobe plugin. Using the print icon in the toolbar of the PDF plugin works as expected.
Is there a way to invoke the print dialog on an inline PDF in Firefox 19 from Javascript?
Choose File > Print. Choose Adobe PDF as the printer in the Print dialog box. To customize the Adobe PDF printer setting, click the Properties (or Preferences) button. ... Click Print.
I tried the provided JSFiddle demo, with Firefox 22 and NoScript. Interestingly, when I first opened the fiddle, the iframe's content was blocked by NoScript, but the print dialog readily popped up! I clicked "Ok", and I got a taskbar toast saying the document about.blank was sent to the printer. Sure enough, I checked the printer and it spit out a nice white page. Not useful...
Now, after telling NoScript to "temporarily allow" the domain of the PDF (irs.gov), I reproduce the bug :
Error: Permission denied to access property 'print'
This other question made me wonder if it was a problem of same origin policy. So I tested it on my own webserver, with a PDF document hosted on the same machine. And... no dice !
I then tried my test page in IE 9 and Chrome. Both of them do show the print dialog, but when I print the document, in the case of IE 9, it's actually printing about:blank, and Chrome prints a grey rectangle saying "Loading"... looks like it's printing the whole page, not just the document in the iframe.
So, I agree with Jason Sperske that this doesn't seem possible.
UPDATE : this answer offers a solution that "just works", but only for PHP files generated by the Fpdf library...
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
.
Please try the following code, it's working:
window.frames.myPdfFrame.focus();
window.print();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With