I have pdf files stored on my server.
I would like the user to be able to click a link/button and have a print dialog popup so they can print the pdf. I tried convincing them that its not a big deal to click download, then print it from the browser tab in which it opens, but they are fickle. :)
I have tried a few javascript solutions, mostly what I end up with is:
contentWindow is not defined
My js snippet is as follows
a = $("a:contains('Download PDF')")
url = a.attr('href')
uid = unique_id()
uid = "abc_" + uid
ifrm = $("<iframe width='500px' src='" + url + "' id='" + uid + "' name='" + uid + "' onload='this.contentWindow.print()'></iframe>")
$('body').append(ifrm)
I have also tried
...
ifrm = $("<iframe width='500px' src='" + url + "' id='" + uid + "' name='" + uid + "' ></iframe>")
$('body').append(ifrm)
pdf = document.findElementById(uid)
pdf.contentWindow.print();
And a few other variations with the same result. Or I get a print of "About:Blank" presumably because print is called before the document is loaded in the iframe.
The pdf opens and renders in the iframe.
Any ideas