Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html: print() embed file

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?

like image 492
Rps Avatar asked Feb 21 '23 17:02

Rps


1 Answers

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

like image 146
agarcian Avatar answered Feb 23 '23 05:02

agarcian