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?
Please try the following code, it's working:
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 :
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 thepdfjs.disabled
property totrue
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 toapplication/pdf
.