Html: print () embed file

I am showing pdf inside html using:

<embed id="print" src="file.pdf" type="application/pdf" width="100%" height="100%"> 

I would like to create a button that prints this file.

I thought it would be something like this; but it does not work.

<button onClick="javascript:document.getElementById('print').print();">

Does anyone know how I can call the print function in an embedded file?

+3
source share
1 answer
<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")

+8
source

All Articles