html: print() embed file

embed, html, javascript, pdf, printing

Solution

<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")`

Problem

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?

Original source