html: print() embed file
33,561
<script type="text/javascript">
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
}
</script>
You can call this function printPDF("http://mywebsite.com/myfile.pdf")
Comments
-
Rps over 3 years
I am showing a pdf inside a html using:
<embed id="print" src="file.pdf" type="application/pdf" width="100%" height="100%">
I would like to create a button that prints that file.
I thought it would be something like this; but it isn't working.
<button onClick="javascript:document.getElementById('print').print();">
Anybody an idea how I can call the print function on an embedded file?
-
Rps about 12 yearsThanx Agercian. the script does open a new window, but the print() isn't doing anything. I am using chrome to do this.
-
agarcian about 12 yearsIs the PDF hosted in the same domain that the page hosting this code is? I believe if you are trying to print from a different server it will give an 'Unsafe Javascript' message.
-
Rps about 12 yearsno the pdf is accessed form localserver, stored on my c:/ drive
-
Max Malyk over 10 yearsprintPDF is a FF addon - addons.mozilla.org/en-US/firefox/addon/printpdf, it does not help to resolve the question for other browsers...
-
Raghavendra N almost 2 yearsChaining the print method will work -
window.open(pdfUrl).print()